laravel 5.6 修改auth 重置密码邮件

1.输入 php artisan make:notification RestPassword ,在 app\notification 下创建 RestPassword.php

然后修改 App\User:

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 

将自动创建 email.blade.php 模版,我这里并不想修改 

3.更改邮件内容,修改第一步创建的 app\notification\RestPassword.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('如果您本人未进行密码重置,您可以不必采取进一步操作!');
    }

}
沿着 Illuminate\Notifications\Messages\MailMessage 可以找到 Illuminate\Notifications\Messages\SampleMessage 
其中包含了 subject, salutation ...

下面说说官网上的东西

自定义

自定义认证 Guard

在配置文件 auth.php 中,可以配置多个“guards”,以便用于实现基于多用户表的独立认证,你可以通过重写内置的 ResetPasswordController 控制器上的 guard 方法来使用你所选择的 guard,该方法将会返回一个 guard 实例:

use Illuminate\Support\Facades\Auth;

protected function guard()
{
    return Auth::guard('guard-name');
}

//注:guard-name是你在config/auth.php里面配置的broker
 'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],

自定义密码 broker

在配置文件 auth.php 中,可以配置多个密码,以便用于重置多个用户表的密码 broker,同样,可以通过重写自带的 ForgotPasswordController 和 ResetPasswordController 控制器中的 broker 方法来使用你所选择的 broker:

use Illuminate\Support\Facades\Password;

/**
 * 获取密码重置期间所使用的broker.
 *
 * @return PasswordBroker
 * @translator laravelacademy.org
 */
protected function broker()
{
    return Password::broker('name'); //这个是你在config/auth.php里面配置的broker,如下注释
}

//注:这个是你在config/auth.php里面配置的broker
 'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可以吧可以吧

打赏可以获得大长腿妹子微信

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值