RobertBaelde's avatar

dispatch queue outside controller

Hi,

I want to dispatch a queue from a class, is there a way to do this? In laravel 5 you can use:

<?php

namespace App;

use Illuminate\Foundation\Bus\DispatchesJobs;

class ExampleClass
{
    use DispatchesJobs;
}

But in lumen that doesn't work...

0 likes
5 replies
trompx's avatar

I am struggling doing the exact same thing, the way common features are implemented differently in laravel and lumen totally sucks.

trompx's avatar

Using the following works in lumen.

app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($job);

But in my case I try to use the same code for lumen and laravel so if someone has a solution that allow $this->dispatch($job) to work with lumen, I am all ears :)

2 likes
trompx's avatar
trompx
Best Answer
Level 1

Ok I managed to make this work by copying the Illuminate\Foundation\Bus\DispatchesJobs file from laravel to lumen in a app\Traits folder and using it the same way as laravel :)

Cheers, Xavier

zarsi's avatar

Hello. Faced same issue yesterday and found it here in Lumen: use Laravel\Lumen\Routing\DispatchesJobs;

1 like

Please or to participate in this conversation.