【发布时间】:2021-12-16 12:37:19
【问题描述】:
我正在测试我的密码重置通知,看看它是否响应 APP_URL 中的更改,很遗憾它没有。 尽管如此,它还是会响应 APP_NAME 环境变量的变化。 我清除了我的缓存,我清除了我的视图,我运行了 php artisan optimize:clear,不幸的是没有任何效果。
奇怪的是它响应的是 APP_NAME 而不是 APP_URL 的变化...
这是我的环境文件
APP_NAME=WP
APP_ENV=local
APP_KEY=base64:uqkPjWhwt7orbinLRlRN+BNn6BxbdIRHSV4dG4dw5S0=
APP_DEBUG=true
APP_URL=http://example.com
这是未更改的 ResetPassword toMail() 函数
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
if (static::$createUrlCallback) {
$url = call_user_func(static::$createUrlCallback, $notifiable, $this->token);
} else {
$url = url(route('password.reset', [
'token' => $this->token,
'email' => $notifiable->getEmailForPasswordReset(),
], false));
}
//dd(env('APP_URL')); returns http://example.com
// dd(config('app.url')); returns http://example.com
// dd($url); returns http://127.0.0.1:8000/{token}?email!
return (new MailMessage)
->subject(Lang::get('Reset Password Notification'))
->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
->action(Lang::get('Reset Password'), $url)
->line(Lang::get('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
->line(Lang::get('If you did not request a password reset, no further action is required.'));
}
【问题讨论】:
-
我使用 dd 查看扩展通知的 ResetPasswod 类中 URL 的样子,不幸的是,它显示的不是 APP_URL 中的本地主机。当我使用 dd 获取 APP_URL 变量时,它会显示我设置的变量。这可能是什么问题?
-
你使用的是哪个版本的 laravel?您是否停止了该项目的服务并再次运行它?
-
Laravel 8。是的,我再次运行该项目。在 toMail 方法中,dd(env('APP_URL')) 和 dd(config('app.url')) 返回域名。但是 dd($url) 使用 localhost ...
-
我认为问题在于它没有使用我的 url(尽管它已在 env 文件和配置文件中定义)作为我的路由的根
-
把你的代码示例和你的 env 文件放在一起会很有帮助,有时你错过的东西可以被新鲜的眼睛抓住
标签: php laravel environment-variables