laravel 5.5 修改auth 重置密码邮件
2018年8月1日1.输入 php artisan make:notification ResetPassword 创建修改密码通知类
2.修改user模型定义邮件发送方法
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php 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)); } } |
3.输入 php artisan vendor:publish –tag=laravel-notifications 创建邮件发送的模板
4.修改发送内容,添加token
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<?php 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('如果您本人未进行密码重置,您可以不必采取进一步操作!'); } } |