You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 10队列验证邮件失败:Route [verification.verify]未定义

解决Laravel 10队列验证邮件的RouteNotFoundException问题

问题原因

队列任务执行时,生成验证链接的过程无法找到verification.verify路由,本质是原VerifyEmail类的链接生成逻辑依赖请求上下文,而队列后台执行时无请求上下文,导致路由解析失败。

修复方案

1. 重写验证链接生成方法

修改你的QueuedVerifyEmail类,手动实现验证URL的生成,脱离请求上下文依赖:

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Support\Facades\URL;

class QueuedVerifyEmail extends VerifyEmail implements ShouldQueue
{
    use Queueable;

    /**
     * 生成验证链接
     *
     * @param  mixed  $notifiable
     * @return string
     */
    protected function verificationUrl($notifiable)
    {
        return URL::temporarySignedRoute(
            'verification.verify',
            now()->addMinutes(60),
            [
                'id' => $notifiable->getKey(),
                'hash' => sha1($notifiable->getEmailForVerification()),
            ]
        );
    }
}

2. 配置与缓存检查

  • 确保.env中的APP_URL配置正确(例如APP_URL=http://your-domain.com),生成的链接会自动带上v1前缀。
  • 清除路由缓存并重启队列worker:
    php artisan route:clear
    php artisan queue:restart
    

更优实现方式

你当前通过扩展VerifyEmail类实现队列的方案是Laravel官方推荐的方式,无需额外替换。如果想简化代码,也可以直接在User模型的通知方法中动态指定队列,但核心还是要保证验证链接的生成不依赖请求上下文,推荐保持现有结构并修复链接生成逻辑即可。

内容的提问来源于stack exchange,提问作者anas ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 14:54:53