我将尝试在通知邮件中添加用户的名字。目前,Laravel通知邮件的开头如下所示:
用户模型是否自动绑定到通知类?如何在视图中添加用户名?
Hello,
我希望您能将其更改为:
Hello Donald,
现在,我的设置是这样的。以下示例是有关密码重置通知电子邮件的:
用户模型:
public function sendPasswordResetNotification($token)
{
$this->notify(new PasswordReset($token));
}
App\Notifications\PasswordReset:
class PasswordReset extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', 'https://laravel.com')
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
用户模型是否自动绑定到通知类?如何在视图中添加用户名?
$user->first_name
或$first_name
,它会抛出未定义变量的错误。因此,我认为用户对象需要从通知类中发送? - Neel