1.輸入 php artisan make:notification RestPassword ,在 app\notification 下建立 RestPassword.phpphp
而後修改 App\User:laravel
namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use App\Notifications\ResetPassword as RestPasswordNotification; // 替換 class User extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', 'college', 'class', 'phone' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; public function sendPasswordResetNotification($token) { $this->notify(new RestPasswordNotification($token)); } }
2.輸入 php artisan vendor:publish --tag=laravel-notifications app
將自動建立 email.blade.php 模版,我這裏並不想修改 this
3.更改郵件內容,修改第一步建立的 app\notification\RestPassword.php url
namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; class ResetPassword extends Notification { use Queueable; /** * The password reset token. * * @var string */ public $token; /** * 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('XXXX') ->salutation('XXX') ->line('您之因此收到這封郵件是由於咱們收到了您重置密碼的申請。') ->action('Reset Password', url(config('app.url').route('password.reset', $this->token, false))) ->line('若是您本人未進行密碼重置,您能夠沒必要採起進一步操做!'); } }
沿着 Illuminate\Notifications\Messages\MailMessage 能夠找到 Illuminate\Notifications\Messages\SampleMessage 其中包含了 subject, salutation ...