I am trying to add the user's first name in the notification emails. At the moment, Laravel notification emails starts like:
Hello,
And I want to change it to:
Hello Donald,
Right now, I have a set-up like this. This example is for a Password Reset Notification email:
User Model:
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 [
//
];
}
}
Is the User Model automatically binded with the Notification Class? How can I add the username in the view?
Hello!
in the notification email which is the default. If I add$user->first_name
or$first_name
to the blade, it throws the undefined variable error. So I believe the user object needs to be sent from notification class? – PratiquePasswordReset
. – Pratique