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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47438187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:59:50  来源:igfitidea点击:

Receiving a wrong reset password link in Laravel 5.5

phplaravellaravel-5laravel-5.4laravel-5.5

提问by Rachid Azzanati

I'am using php artisan make:auth in my project, everything work perfectly except the sent link to reset passwords. The link didn't contain the correct url, the project name is missed. This is the link sent before I proceed to the notification solution: http://localhost/password/reset/05929a8e465ddfa123a4c068da455cf63c3b9b90ec500a0e1045f092bbd0d97aI have create this Method in my User class :

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

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

and then I have created a notification class that contain toMail method to override the existing one in \vendor\laravel\framework\src\Illuminate\Auth\Notifications\ResetPassword.php:

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

The link I got now worked as expected, and this is the sent link: http://localhost/myproject/public/password/reset/435e453cfa30c968c96ded21c964d70e21459d6ae6ffae8f4972c229773e8a6a. but, I don't know if I change toMail method in ResetPassword.php directly instead of doing it by notification will cause any problems in Production or something else, I will change only ->action part.

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

Thank's a lot.

非常感谢。

回答by patricus

In Laravel 5.5, the built in notification builds the url with this code:

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

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

The value of config('app.url')can be changed by setting the APP_URLvariable in your .envfile. If you set the APP_URLvalue, you do not need to go through the trouble of overriding the built in functionality.

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

APP_URL=http://localhost/myproject/public

回答by Salah

In config/app.php

config/app.php

Change

改变

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

To:

到:

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