my function in controller Calling parallel and i create a job for use queue in laravel Because parallel call causing the problem
I create queue as follows :
public function serve($id)
{
$this->dispatch(new OrderServeJob($id));
return response()->json(true);
}
and i run:
php artisan queue:work
But I have a problem with this method
I want laravel to wait until the queue ends up and then return response()->json(true)
and after redirect user to another address
If you want your job to be handled before the call ends you should use the sync
driver for your Job. You can do this customizing the Job connection to use in your job:
class OrderServeJob implements ShouldQueue {
public $connection = 'sync'; // <---
//
}
You can take a look a this (and others) queue configuration in your config/queue.php
file:
'connections' => [
'sync' => [
'driver' => 'sync',
],
//
]
Check the Customizing The Queue & Connection section of the documentation.