Laravel Queue Tips
2 min readOct 4, 2022
you should save this
1-) Push a job to the queue
Push method in 4 different ways
//push a job to the queue
Queue:push(new PaymentProcess($order));dispatch(new PaymentProcess($order));(new PaymentProcess($order))->dispatch();PaymentProcess::dispatch($order);
2-) Push the job after a given number of seconds
// push the job after a given number of seconds
Queue::later(15,new PaymentProcess($order));dispatch(new PaymentProcess($order))->delay(15);(new PaymentProcess($order))->dispatch()->delay(15);PaymentProcess::dispatch($order)->delay(15);
3-) Push on specific queue
//Push on specific queueQueue::pushOn('orders', new PaymentProcess($order));dispatch(new PaymentProcess($order))->onQueue('orders');(new PaymentProcess($order))->dispatch()->onQueue('orders');PaymentProcess::dispatch($order)->onQueue('orders');
4-) Dispatch conditionally
// dispatch conditionally
PaymentProcess::dispatchIf($order->isPaid(),$order);PaymentProcess::dispatchUnless($order->isCancelled(), $order);
5-) Push on spesific queue with time delay
// push on spesific queue with time delay
Queue::laterOn('orders', 15 new PaymentProcess($order));
6-) Push multiple Jobs
// Push multiple Jobs
Queue::bulk([
new PaymentProcess($order),
new PaymentCompleted($user)
]);
7-) Push multiple to specific queue
//push multiple to specific queue
Queue::bulk([
new PaymentProcess($order),
new PaymentCompleted($user)
], null, 'orders');
Thank you for reading this article.
If you find this article useful please kindly share it with your network and feel free to use the comment section for questions, answers, and contributions.
You might also like :
- Read Also : Laravel Tips and Tricks #2
- Read Also : Laravel 9 Traits Example
- Read Also : Laravel Eloquent Tips and Tricks
- Read Also : Upgrade from Laravel 8 to 9