diff --git a/queues.md b/queues.md index d6394f53abe..b15c90be773 100644 --- a/queues.md +++ b/queues.md @@ -1415,20 +1415,18 @@ Sometimes you may need to cancel a given batch's execution. This can be accompli } } -As you may have noticed in previous examples, batched jobs should typically check to see if the batch has been cancelled at the beginning of their `handle` method: +As you may have noticed in the previous examples, batched jobs should typically determine if their corresponding batch has been cancelled before continuing execution. However, for convenience, you may assign the `SkipIfBatchCancelled` [middleware](#job-middleware) to the job instead. As its name indicates, this middleware will instruct Laravel to not process the job if its corresponding batch has been cancelled: + + use Illuminate\Queue\Middleware\SkipIfBatchCancelled; /** - * Execute the job. + * Get the middleware the job should pass through. * - * @return void + * @return array */ - public function handle() + public function middleware() { - if ($this->batch()->cancelled()) { - return; - } - - // Continue processing... + return [new SkipIfBatchCancelled]; }