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(4mo ago)2417MITPHPPHP ^8.2

Since Feb 21Pushed 1mo 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 2d ago

READMEChangelog (5)Dependencies (16)Versions (8)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 or 13

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

44

—

FairBetter than 90% of packages

Maintenance84

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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 ~13 days

Recently: every ~18 days

Total

7

Last Release

54d 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 (6 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/ai

The official AI SDK for Laravel.

1.0k3.2M193](/packages/laravel-ai)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.2M208](/packages/illuminate-broadcasting)[illuminate/queue

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M306](/packages/laravel-horizon)

PHPackages © 2026

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