我想向所有用戶發送通知,并希望將所有用戶資料傳遞給 MyNotification 類
Notification::send($users, new MyNotification($users));
這樣 MyNotification 類建構式將接收所有用戶的集合并回傳錯誤
此集合實體上不存在屬性 [first_name]
我的通知.php
public function toMail($notifiable)
{
return (new MailMessage)
->line('Dear ' . $this->users->first_name . ',')
->line('Your profile has been updated.')
->action('View Profile', url('/'));
}
所以我的問題是,如何將所有用戶資料傳遞給 MyNotification 類,或者我需要在 MyNotification 類中運行 foreach 回圈來獲取每個用戶的 first_name ?
uj5u.com熱心網友回復:
在您的 toMail 函式中,您將使用 $notifiable 變數(即用戶)而不是嘗試使用 users 集合。
public function toMail($notifiable)
{
return (new MailMessage)
->line('Dear ' . $notifiable->first_name . ',')
->line('Your profile has been updated.')
->action('View Profile', url('/'));
}
我也不確定為什么要將所有用戶都傳遞給 MyNotification,這不是必需的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/511475.html
上一篇:如何在“useForm”變數中分配輸入值引數。慣性/Laravel
下一篇:減少庫存管理中的產品數量
