在Laravel 5.5中接收错误的重置密码链接

问题描述 投票:3回答:1

我在我的项目中使用php artisan make:auth,除了发送的重置密码链接外,一切都很完美。该链接未包含正确的URL,错过了项目名称。这是在我进入通知解决方案之前发送的链接:http://localhost/password/reset/05929a8e465ddfa123a4c068da455cf63c3b9b90ec500a0e1045f092bbd0d97a我在我的User类中创建了此方法:

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

然后我创建了一个包含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.');
}

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

非常感谢。

php laravel laravel-5 laravel-5.4 laravel-5.5
1个回答
14
投票

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

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

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

APP_URL=http://localhost/myproject/public

0
投票

config/app.php

更改

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

至:

'url' => env('APP_URL', 'http://wwww.yourwebsite.com'),
© www.soinside.com 2019 - 2024. All rights reserved.