Laravel mail notification with pusher and mailtrap

Laravel で pusher を使った notification を受けて mailtrap 経由で通知メールを送る。

monteecristoo.hatenablog.com

上記の続き

@.env mailtrap のアカウント情報を記入

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=YOUR MAILTRAP USER NAME
MAIL_PASSWORD=YOUR MAILTRAP PASSWORD
MAIL_ENCRYPTION=null

 

@notification/NewFriendRequest.php

notification イベントに mail を追加

mail 本文の設定

public function via($notifiable)
{
return ['mail''broadcast', 'database'];
}

public function toMail($notifiable)
{
return (new MailMessage)
->line('You received a new frined request from' . $this->user->name )
->action('View profile', route('profile', ['user_id'=> $this->user->id ]))
->line('Thank you for using our application!');
}

f:id:monteecristoo:20171027210742j:plain

上記のような通知メールが発行される。