I am getting data from a Model, then passing it to generate a PDF attachment to be emailed.
However, I have a challenge getting the data on the PDF view side as I am required to pass as an array. See below;
$allTransaction = TblAirtimePurchaseInfo::where('org_name', '=', $user->org_name)->get();
$allTransaction = (array) $allTransaction;
$emails = $user->email;
$name = ['first_name' => $user->first_name];
Mail::send('emails.send_transactions_email', $name, function ($m) use ($emails, $allTransaction) {
$pdf = PDF::loadView('PDF.sendAllTransaction',['allTransaction' => $allTransaction])->stream();
$m->attachData($pdf, 'Transactions_for_' . date("Y-m-d") . '.pdf');
$m->to($emails)->subject('Transaction ' . date("Y-m-d") );
});
On the PDF.sendAllTransaction view
I am trying to get the values through a loop;
<table class="table no-margin" id="data">
<thead>
<tr>
<th> ID </th>
<th> Date </th>
<th> Amount </th>
<th> Phone Number </th>
</tr>
</thead>
<tbody>
@php
$allTransaction = (object) $allTransaction;
$id = 1;
@endphp
@foreach($allTransaction as $detail)
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
@endforeach
</tbody>
</table>
However, I get Trying to get property of non-object error. How can I get the values on the view?
Anyone?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire