人気のPHP WEBアプリケーションフレームワークLaravelのTipsを記録していきます

Laravelのパスワード再発行メールを日本語化する

● Laravelのパスワード再発行メールを日本語化する

1. /app/Notifications/ResetPasswordNotification.php を次の内容で作成する

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class ResetPasswordNotification extends Notification
{
    public $token;

    public function __construct($token)
    {
        $this->token = $token;
    }

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

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('パスワードの再発行')
            ->line("パスワード再発行のリクエストを受け付けました。こちらのボタンを押してパスワードを再設定してください。")
            ->action('パスワードを再発行する', route('password.reset', $this->token))
            ->line('もしこのメールに心当たりがない場合はこのメールを破棄してください。');
    }
}

2. モデルファイル /app/User.php に設定する

/app/User.php

    /**
     * オリジナルのパスワード再発行メールを送信する
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new \App\Notifications\ResetPasswordNotification($token));
    }

以上です。簡単ですね。

No.1848
08/28 12:18

edit