为默认的身份验证路由添加前缀

时间:2018-07-07 15:20:25

标签: laravel laravel-5.6

我已将前缀用户添加到默认身份验证路由,以便可以实现example.com/user/login路由。除发送到用户电子邮件地址的密码重置电子邮件外,其他所有内容均正常运行。单击电子邮件中的链接时,它将转到默认的重置路由。如何在电子邮件中的此链接中添加前缀用户。

感谢您的帮助。

如果有帮助,这里是代码

Route::group(['prefix' => 'user'], function () {
      Auth::routes();
      Route::get('/home', 'HomeController@index')->name('home');
    });

1 个答案:

答案 0 :(得分:1)

您需要创建用于重置密码的通知类

php artisan make:notification MailResetPasswordToken

在此之后,编辑在新文件夹App\Notifications中找到的该文件,并将url('password/reset', $this->token)更改为url('user/password/reset', $this->token)

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class MailResetPasswordToken extends Notification
{
    use Queueable;

    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("Reset your password")
                    ->line("Hey, did you forget your password? Click the button to reset it.")
                    ->action('Reset Password', url('user/password/reset', $this->token))
                    ->line('Thankyou for being a friend');
    }

}

使用User.php用户模型中的本地实现覆盖发送密码重置特征。确保您的User模型应该使用Notifiable特征

/**
 * Send a password reset email to the user
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new MailResetPasswordToken($token));
}

将这些类导入User模型

use App\Notifications\MailResetPasswordToken;
use Illuminate\Notifications\Notifiable;