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

Laravel 5.5通知实现ShouldQueue时监听器失效问题咨询

Hey there, let's break down how to fix this issue with your queued Laravel 5.5 notifications not firing the NotificationSent event properly:

Troubleshooting Queued Notification Events in Laravel 5.5

First, let's align on core behavior: When your notification implements ShouldQueue, the NotificationSent event doesn't fire immediately when you dispatch the notification—it fires after the queue worker processes the notification task. That's a key detail easy to overlook!

Here's your step-by-step debug plan:

  • Verify your queue is actually running
    If you haven't started a queue worker, the notification will sit in your queue storage (database/Redis/etc.) forever, and the event will never trigger. Run this command in your terminal:

    php artisan queue:work
    

    Also double-check your .env queue driver config (e.g., QUEUE_DRIVER=database) matches your setup, and ensure there are no failed tasks clogging things up (check the failed_jobs table if using database driver).

  • Check for serialization issues in your notification class
    Queued notifications get serialized before being pushed to the queue. If your notification has properties that can't be serialized (like closures, resource objects, or un-serializable custom classes), those properties will be lost by the time the queue worker processes it—resulting in empty data in your NotificationSent event.
    Make sure all properties in your notification class are primitive types (strings, integers, arrays) or implement the Serializable interface if they're custom objects.

  • Confirm your event listener is registered correctly
    Head to your app/Providers/EventServiceProvider.php and ensure you've mapped the NotificationSent event to your listener:

    protected $listen = [
        \Illuminate\Notifications\Events\NotificationSent::class => [
            \App\Listeners\YourNotificationListener::class,
        ],
    ];
    

    If you just added this mapping, run php artisan event:generate to auto-create the listener file (if you didn't build it manually).

  • Debug with logging to see what data is actually coming through
    In your listener's handle() method, add a log entry to inspect the event data:

    use Illuminate\Support\Facades\Log;
    
    public function handle(\Illuminate\Notifications\Events\NotificationSent $event)
    {
        Log::info('Notification Sent Event Data', [
            'notifiable_id' => $event->notifiable->id ?? 'null',
            'notification_class' => get_class($event->notification),
            'channel' => $event->channel,
            'response' => $event->response
        ]);
    }
    

    Check your storage/logs/laravel.log file after the queue worker runs—this will tell you exactly which data is missing or null.

  • Note on event execution context
    Remember: When using queued notifications, the NotificationSent event fires in the queue worker's process, not the original request process. If you were expecting to catch the event during the initial request, that won't happen—you'll need to handle it asynchronously alongside the queued task.

内容的提问来源于stack exchange,提问作者Summer Developer

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 07:08:57