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

Add prefix to default auth routes

我已将前缀用户添加到默认身份验证路由,以便我可以实现示例。com/user/login 路由。除了发送到用户电子邮件地址的密码重置电子邮件外,一切正常。单击电子邮件中的 link 时,它会转到默认重置路由。如何在电子邮件中向此 link 添加前缀用户。

感谢任何帮助。

下面是代码,如果有帮助的话

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

您需要为密码重置创建通知class

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));
}

将这些 class 导入到 User 模型

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