Laravel 通知未响应 APP_URL 更改

Laravel Notifications not responding to APP_URL changes

我正在测试我的密码重置通知,看它是否响应 APP_URL 中的更改,不幸的是它没有。 尽管如此,它还是会响应 APP_NAME 环境变量的变化。 我清除了我的缓存,我清除了我的视图,我 运行 php artisan optimize:clear 不幸的是没有任何效果。

什么是 st运行ge 是它响应 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.'));
}

在更改 .env 文件后,您可能需要 运行 php artisan cache:clearphp artisan config:clear

https://laravel.com/docs/6.x/configuration#configuration-caching

排队的通知将在构建 url 时使用 APP_URL 配置值。但是,非队列通知将在构建 urls 时使用 HTTP 请求信息。

ResetPassword 通知不是排队通知,因此它将使用触发通知的原始 HTTP 请求中的 url。在这种情况下,看起来您正在 http://127.0.0.1:8000 进行本地测试,因此这是将用于构建密码重置 link.

的基础 url

如果通知已排队,则将使用运行控制台内核的队列工作程序发送通知。控制台内核构建一个假请求,它根据 APP_URL 配置值设置基础 url。


注意,有一段时间 ResetPassword 通知专门在通知中使用 config('app.url') 构建 URL。这是在 5.4.22 中引入的,但后来在 6.18.7 中删除了。从那时起,它的行为就像所有其他通知一样。