我在我的项目中使用 php artisan make:auth,除了发送的用于重置密码的链接外,一切正常。 链接不包含正确的 url,项目名称丢失。 这是在我继续通知解决方案之前发送的链接: http://localhost/password/reset/05929a8e465ddfa123a4c068da455cf63c3b9b90ec500a0e1045f092bbd0d97a 我在我的用户类中创建了这个方法:
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 方法而不是通过通知来更改会导致生产或其他方面的任何问题,我将只更改 ->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
关于php - 在 Laravel 5.5 中收到错误的重置密码链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47438187/