how do you switch between ShouldQueue and Sync in a class?
We have got an endpoint which accepts an argument whether a job should be fired immediately or later.
In both cases the same logic should be executed but in one scenario I expect and answer back and the other one should be handled async.
I am aware of implementing "ShouldQueue" and use the "InteractsWithQueue"-Trait but how can we use this in one situation and not use it in the other?
Can you programatically set whether a request should be queued or not or are there better ways to do this? Thanks
handle()method in your controller? If you want to run it in the queue, or "offline", you can use the dispatcher to queue it like normal.$job = app(\App\Jobs\MyJob::class);), any classes you type hint in the constructor will automatically be passed for you. If you callhandle()manually and it requires you to pass parameters, then just pass the parameters when you call it. No need to worry about those parameters when you queue it - I believe the service container will automatically inject the parameters when its run from the queue.