3
使用背包拉拉维尔(爱它)。如何将关系数据传递给Laravel 5.3中的邮件?
所以,我每次有这样的一段代码的用户存储的数据(FinanceCrudController):
$finance = $request->all();
if ($request->input('shouldPay') == 'Yes') {
Mail::to($request->user())->send(new NewBill($finance));
return parent::storeCrud();
}
else {
return parent::storeCrud();
}
而这正是我可邮寄(NewBill)看起来像:
class NewBill extends Mailable
{
use Queueable, SerializesModels;
/**
* The finance instance.
*
* @var Finance
*/
public $finance;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($finance)
{
//
$this->finance = $finance;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.newbill');
}
}
然后,我可以通过拨打newbill.blade.php来传递财务表中的数据,如下所示:
{{ $finance['name'] }}
但是,我无法弄清楚的是如何获取关系数据。
我正在使用分类表来处理类别。所以,如果我叫类别上我的刀片观点:
{{ $finance['category_id'] }}
我只是要得到有关的分类表中的字段的ID号。
如何在电子邮件中生成实际类别名称而不是字段的ID?
完美!谢谢你的手! – Rosenberg