Laravel - Queues - Cancelling Batches

Sometimes you may need to cancel a given batch's execution. This can be accomplished by calling the cancel method on the Illuminate\Bus\Batch instance:

    
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if ($this->user->exceedsImportLimit()) {
            return $this->batch()->cancel();
        }
    
        if ($this->batch()->cancelled()) {
            return;
        }
    }
	

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:

    
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if ($this->batch()->cancelled()) {
            return;
        }
    
        // Continue processing...
    }