在 Laravel 5.5 收到错误的重置密码 link

Receiving a wrong reset password link in Laravel 5.5

我在我的项目中使用 php artisan make:auth,除了发送 link 重设密码外,一切正常。 link 不包含正确的 url,项目名称丢失。 这是在我继续通知解决方案之前发送的 link: http://localhost/password/reset/05929a8e465ddfa123a4c068da455cf63c3b9b90ec500a0e1045f092bbd0d97a 我在我的用户中创建了这个方法 class :

public function sendPasswordResetNotification($token) {
    $this->notify(new ResetPasswordNotification($token));
}

然后我创建了一个通知 class,其中包含 toMail 方法以覆盖 \vendor\laravel\framework\src\Illuminate\Auth\Notifications\ResetPassword 中的现有方法。php:

class ResetPasswordNotification extends Notification {
use Queueable;
...
...
    public function toMail($notifiable) {
    return (new MailMessage)
        ->line('You are receiving this email because we received a password reset request for your account.')
        ->action('Reset Password', route('password.reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}

我得到的link现在按预期工作了,这是发送的link: http://localhost/myproject/public/password/reset/435e453cfa30c968c96ded21c964d70e21459d6ae6ffae8f4972c229773e8a6a。但是,我不知道如果我直接更改 ResetPassword.php 中的 toMail 方法而不是通过通知来更改会导致生产或其他方面的任何问题,我将只更改 ->action 部分。

非常感谢。

在 Laravel 5.5 中,内置通知使用以下代码构建 url:

url(config('app.url').route('password.reset', $this->token, false)))

可以通过在 .env 文件中设置 APP_URL 变量来更改 config('app.url') 的值。如果您设置 APP_URL 值,则无需经历覆盖内置功能的麻烦。

APP_URL=http://localhost/myproject/public

config/app.php

改变

'url' => env('APP_URL', 'http://localhost'),

收件人:

'url' => env('APP_URL', 'http://wwww.yourwebsite.com'),