PHPackages                             smartgeomatics/laravel-deferred-batch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. smartgeomatics/laravel-deferred-batch

ActiveLibrary[Queues &amp; Workers](/categories/queues)

smartgeomatics/laravel-deferred-batch
=====================================

Deferred batch construction for Laravel job chains

v1.04(2mo ago)262MITPHPPHP ^8.2

Since Feb 21Pushed 2mo agoCompare

[ Source](https://github.com/smartgeomatics/laravel-deferred-batch)[ Packagist](https://packagist.org/packages/smartgeomatics/laravel-deferred-batch)[ RSS](/packages/smartgeomatics-laravel-deferred-batch/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (16)Versions (7)Used By (0)

Laravel Deferred Batch
======================

[](#laravel-deferred-batch)

A Laravel package that lets you lazily construct and dispatch a job batch from within a job chain. Instead of defining batch jobs at dispatch time, you provide a builder callback that runs when the chain reaches that step — allowing you to build the batch based on runtime state.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 12

Installation
------------

[](#installation)

```
composer require smartgeomatics/laravel-deferred-batch
```

The service provider is auto-discovered via Laravel's package discovery.

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

Use `DeferredBatch` as a step in a job chain. The builder callback must return a `PendingBatch` or `null`.

```
use Illuminate\Support\Facades\Bus;
use Illuminate\Bus\PendingBatch;
use SmartGeomatics\DeferredBatch\DeferredBatch;

Bus::chain([
    new PrepareDataJob,

    new DeferredBatch(function () {
        $items = Item::where('status', 'pending')->get();

        if ($items->isEmpty()) {
            return null; // skip batch, continue chain
        }

        return Bus::batch(
            $items->map(fn ($item) => new ProcessItemJob($item))
        )->name('Process pending items');
    }),

    new FinalizeJob,
])->dispatch();
```

### Skipping the Batch

[](#skipping-the-batch)

Return `null` from the builder to skip the batch step entirely. The chain continues with the next job as normal.

```
new DeferredBatch(function () {
    if (! $this->shouldRunBatch()) {
        return null;
    }

    return Bus::batch([...]);
})
```

### Using an Invokable Class

[](#using-an-invokable-class)

For complex builders or when you need a serializable class instead of a closure:

```
class BuildReportBatch
{
    public function __invoke(): ?PendingBatch
    {
        $reports = Report::whereNull('generated_at')->get();

        if ($reports->isEmpty()) {
            return null;
        }

        return Bus::batch(
            $reports->map(fn ($report) => new GenerateReportJob($report))
        );
    }
}

Bus::chain([
    new DeferredBatch(new BuildReportBatch),
    new SendReportNotificationJob,
])->dispatch();
```

### Queue and Connection Settings

[](#queue-and-connection-settings)

`DeferredBatch` is a standard queueable job, so you can set its queue and connection:

```
Bus::chain([
    (new DeferredBatch(function () {
        return Bus::batch([new SomeJob]);
    }))->onQueue('high')->onConnection('redis'),

    new NextJob,
])->dispatch();
```

How It Works
------------

[](#how-it-works)

1. When the chain reaches the `DeferredBatch` job, it invokes your builder callback.
2. If the builder returns `null`, the chain continues to the next job.
3. If it returns a `PendingBatch`, the remaining chain is attached to the batch's `finally` callback and the batch is dispatched.
4. Any `catch` callbacks from the chain are forwarded to the batch (when the batch does not allow failures).

This means the next job in the chain runs after the batch completes, regardless of whether individual batch jobs failed — as long as the batch itself is not cancelled.

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance85

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

77d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/18ea5ee19eeb883630734ce70647548f51577c8d39044d08992840901aae2d17?d=identicon)[sg-technik](/maintainers/sg-technik)

---

Top Contributors

[![heffaklump90](https://avatars.githubusercontent.com/u/292179?v=4)](https://github.com/heffaklump90 "heffaklump90 (5 commits)")

---

Tags

batchdeferredjob-batchjob-chainlaravellaravel-packagephpqueuequeue-workerslaravelqueuebatchChaindeferred

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/smartgeomatics-laravel-deferred-batch/health.svg)

```
[![Health](https://phpackages.com/badges/smartgeomatics-laravel-deferred-batch/health.svg)](https://phpackages.com/packages/smartgeomatics-laravel-deferred-batch)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.1k84.2M225](/packages/laravel-horizon)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

3786.5k](/packages/harris21-laravel-fuse)[palpalani/laravel-sqs-queue-json-reader

Custom SQS queue reader for Laravel

26109.8k](/packages/palpalani-laravel-sqs-queue-json-reader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
