Search code examples
phplaravellaravel-5laravel-5.3laravel-queue

Is it possible to use a queue inside event-listener in Laravel?


Is it possible to use a queue inside event-listener in Laravel?

Lets say I have a controller QuotesController from where I fire the QuoteCreated event which has a SendNotification listener. And I want to dispatch a queue named EmailToUser from that listener.

Of course I can dispatch the queue directly form Controller but can I dispatch it form a listener?


Solution

  • There is a global dispatch() helper method that you can use anywhere in a Laravel app!

    dispatch(new SomeJob());
    

    And yes you can do this from inside an event listener, or a queue job, or anything else.