php - Laravel 5.7 - 访问通知内视图模板
问题描述
$notifiable
在我的视图模板中访问的正确方法是什么?
我知道$notifiable
是用户,但是当我有以下
public $abc;
public function __construct($abc)
{
$this->abc = $abc;
}
public function toMail($notifiable)
{
$mailMessage = (new MailMessage)
->from('xyz@xyz.com', 'xyz company')
->subject('xyz')
->markdown('emails.news-alert');
return $mailMessage;
}
在我的刀片模板中:
Hello {{ $notifiable->first_name }}
{{ $abc }}
上面会抛出一个错误,因为它无法识别$notifiable
但是,如果我按如下方式传递它,那么它可以工作:
$mailMessage = (new MailMessage)
->from('xyz@xyz.com', 'xyz company')
->subject('xyz')
->markdown('emails.news-alert', ['notifiable' => $notifiable);
不是$notifiable
公共财产 - 我认为它可以作为默认视图提供给视图,而无需通过它?
解决方案
是的,您需要发送要在视图中使用的变量
$mail->markdown(
'emails.news-alert', [
'notificable' => $notificable,
'abc' => $this->abc
]
);
有时你可以使用 compact() 助手,但只有当你有命名变量时(不是 $this->)
$abc = $this->abc;
$mail->markdown('emails.news-alert', compact(['notificable','abc']));
请试试这个,让我知道它是如何工作的:)
推荐阅读
- python - 如何在 Python 中删除列表中的重复元素
- python - 如何将接收到的(承载)访问令牌传递给生成的 REST 客户端,以调用安全的 API-Gateway 端点
- python - Python - datetime.time() 比较将 AttributeError 作为“str”对象返回
- reactjs - 如何使用 Recoil 在 React 组件之外操作全局状态?
- python - 获取 xgboost 线性模型的系数
- r - 如何融化具有多个组和空后缀的data.frame
- angular - Angular - 如何在按钮中添加金额?
- javascript - 如何根据参数插入键并在对象 es6 中更新其值
- html - 为什么会出现我网站上的图像和文字?
- powershell - 使用 Powershell 在现有节之间添加新节