12_4_パスワードリセットメール・カスタマイズ - hpscript/laravel GitHub Wiki

メール本文テンプレート作成

resources/views/mail/passwordreset.blade.php

<body>
	<h1>パスワードリセット</h1>
	<p>以下のボタンを押下し、パスワードリセットの手続きを行ってください。</p>
	<p id="button">
		<a href="{{ $reset_url }}">パスワードリセット</a>
	</p>
</body>

通知クラス

$ php artisan make:notification PasswordResetNotification
app/Notifications/PasswordResetNotification.php が生成される

    public $token;
    protected $title = 'パスワードリセット通知'
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($token)
    {
        //
        $this->token = $token;
    }

    /**
     * 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)
                    ->subject($this->title)
                    ->view(
                        'mail.passwordreset',
                        [
                            'reset_url' => url('password/reset', $this->token),
                        ]);
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }

User.php

use App\Notifications\PasswordResetNotification;
public function sendPasswordResetNotification($token){
        $this->notify(new PasswordResetNotification($token));
    }
⚠️ **GitHub.com Fallback** ⚠️