I am trying to pass an object from my index page to a function and I am trying to differntiate between servers + domains, I can do this on the index page by getting the class name however the variable passed to my function is only the id so I can not see if the object is a server or domain,
if i try and do this it sends the whole object as variable ($invoice):
{!! Form::open(array('class' => 'form-inline', 'method' => 'POST', 'action' => array('InvoiceController@bill', domains.'/'.$invoice))) !!}
controller
public function index() {
$expiry = date('Y-m-d', strtotime('+3 months'));
$servers = Server::where('expiry_date', '<', $expiry)->orderBy('expiry_date', 'asc')->get();
$domains = Domain::where('expiry_date', '<', $expiry)->orderBy('expiry_date', 'asc')->get();
$invoices = $domains->merge($servers);
return view('invoices.index', compact('servers'))->with(compact('domains'))->with(compact('invoices'));
}
form
<tbody>
@foreach($invoices as $invoice)
<?php $reflect = new \ReflectionClass($invoice); ?>
{!! Form::open(array('class' => 'form-inline', 'method' => 'POST', 'action' => array('InvoiceController@bill', $invoice))) !!}
<tr>
@if ($reflect->getShortName() == 'Domain')
<td><a href="{{ route('domains.show', $invoice->id) }}">{{ $invoice->id }}</a></td>
@endif
@if ($reflect->getShortName() == 'Server')
<td><a href="{{ route('servers.show', $invoice->id) }}">{{ $invoice->id }}</a></td>
@endif
<td>{{ $invoice->name }}</td>
<td>{{ $invoice->expiry_date }}</td>
<td>{{ $reflect->getShortName() }}</td>
<td>{{ $invoice->ClientName }}</td>
<td>
@if ($reflect->getShortName() == 'Domain')
{!! link_to_route('domains.edit', 'Edit', array($invoice->id), array('class' => 'btn btn-info')) !!}
@endif
@if ($reflect->getShortName() == 'Server')
{!! link_to_route('servers.edit', 'Edit', array($invoice->id), array('class' => 'btn btn-info')) !!}
@endif
{!! Form::submit('Bill', array('class' => 'btn btn-danger')) !!} </td>
</tr>
{!! Form::close() !!}
@endforeach
</tbody>
controller
public function bill($invoice) {
$invoice = Domain::whereId($invoice)->first();
$bill = new BilltoKashflow();
$bill->bill($invoice);
}
$domainand$server"?