我从模型中获取数据,然后传递它以生成要通过电子邮件发送的PDF附件。
然而,由于我需要作为一个数组传递,因此我需要在PDF视图端获取数据。见下文;
$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") );
});
在 PDF.sendAllTransaction视图
上我试图通过循环获取值;
<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> {{$id ++}} </td>
<td> {{$detail->created_at}}</td>
<td> {{$detail->amount}}</td>
<td> {{$detail->phoneNumber}}</td>
</tr>
@endforeach
</tbody>
</table>
但是,我得试图获取非对象属性错误。如何在视图中获取值?
任何?
答案 0 :(得分:0)
借用@ pdshah3690评论;
这是我在我的控制器上所做的并作为对象传递。
$allTransaction = TblAirtimePurchaseInfo::where('org_name', '=', $user->org_name)->get();
$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', compact('allTransaction'))->stream();
$m->attachData($pdf, 'Transactions_for_' . date("Y-m-d") . '.pdf');
$m->to($emails)->subject('Transaction ' . date("Y-m-d") );
});
视图保持不变。我能够将allTransaction
作为对象传递给我。