From 3b0203b9a2bc34b0bb7a51c2f40ab8022a6deea8 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 7 May 2026 11:08:30 +0100 Subject: [PATCH 1/2] document prepareForDispatch --- queues.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/queues.md b/queues.md index 00298b989c..067cbf10cb 100644 --- a/queues.md +++ b/queues.md @@ -6,6 +6,7 @@ - [Creating Jobs](#creating-jobs) - [Generating Job Classes](#generating-job-classes) - [Class Structure](#class-structure) + - [Preparing Jobs for Dispatch](#preparing-jobs-for-dispatch) - [Unique Jobs](#unique-jobs) - [Debounced Jobs](#debounced-jobs) - [Encrypted Jobs](#encrypted-jobs) @@ -313,6 +314,33 @@ class ProcessPodcast implements ShouldQueue If a job receives a collection or array of Eloquent models instead of a single model, the models within that collection will not have their relationships restored when the job is deserialized and executed. This is to prevent excessive resource usage on jobs that deal with large numbers of models. + +### Preparing Jobs for Dispatch + +Sometimes, you may wish to prepare a job before it is pushed onto the queue, or prevent it from being dispatched if it has no work to do. To do so, implement the `Illuminate\Contracts\Queue\PreparesForDispatch` interface on your job class and define a `prepareForDispatch` method. The `prepareForDispatch` method is executed in the dispatching process, not by a queue worker. Returning `false` from the method will prevent the job from being dispatched to the queue: + +```php +product->isUpToDate()) { + return false; + } + } +} +``` + ### Unique Jobs From 52a42c912304ced39886e0287b5b76e9dcd3fa50 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 7 May 2026 11:11:02 +0100 Subject: [PATCH 2/2] Update queues.md --- queues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queues.md b/queues.md index 067cbf10cb..29015517b7 100644 --- a/queues.md +++ b/queues.md @@ -332,7 +332,7 @@ class UpdateSearchIndex implements ShouldQueue, PreparesForDispatch /** * Prepare the job for dispatch. */ - public function prepareForDispatch(): bool|void + public function prepareForDispatch() { if ($this->product->isUpToDate()) { return false;