Laravel Auth,在注册后将用户凭据传递给 Notification Class
Laravel Auth, Passing user credentials to Notification Class after registering
我正在尝试将用户详细信息传递到我的通知中,以便我可以说:
亲爱的用户名,但不知道如何。此外,我期待在验证用户时获得默认值 URL。所以,基本上我只想更改 toMail 函数中的第一个 ->line()。
在用户模型中:
public function sendEmailVerificationNotification()
{
$this->notify(new CustomVerifyEmail($this->user));
}
在 CustomVerifyEmail Class
public $user;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* 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.'.$this->user->email)
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
您应该能够从传递给 toMail
调用的 $notifiable
中获取 'name',假设它将是您的 User
模型:
line('The introduction to the notification.'. $notifiable->name)
关于自定义发送的 MailMessage
的方法,我已经添加了对您的其他问题的回答。
我正在尝试将用户详细信息传递到我的通知中,以便我可以说: 亲爱的用户名,但不知道如何。此外,我期待在验证用户时获得默认值 URL。所以,基本上我只想更改 toMail 函数中的第一个 ->line()。
在用户模型中:
public function sendEmailVerificationNotification()
{
$this->notify(new CustomVerifyEmail($this->user));
}
在 CustomVerifyEmail Class
public $user;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* 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.'.$this->user->email)
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
您应该能够从传递给 toMail
调用的 $notifiable
中获取 'name',假设它将是您的 User
模型:
line('The introduction to the notification.'. $notifiable->name)
关于自定义发送的 MailMessage
的方法,我已经添加了对您的其他问题的回答。