Laravel Queue Tips

Bayram EKER
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 :

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response