PHPackages                             moe-mizrak/transaction-builder - 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. [Database &amp; ORM](/categories/database)
4. /
5. moe-mizrak/transaction-builder

ActivePackage[Database &amp; ORM](/categories/database)

moe-mizrak/transaction-builder
==============================

TransactionBuilder

v1.0.1(1y ago)32MITPHPPHP ^8.2CI passing

Since Apr 17Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/moe-mizrak/transaction-builder)[ Packagist](https://packagist.org/packages/moe-mizrak/transaction-builder)[ Docs](https://github.com/moe-mizrak/transaction-builder)[ RSS](/packages/moe-mizrak-transaction-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

TransactionBuilder
==================

[](#transactionbuilder)

[ ![reboosty](https://camo.githubusercontent.com/52d4ff26e9b984a2784d285f16637009fecb74006b6ec1016dba72452ba9c3e4/68747470733a2f2f7265626f6f7374792d7265626f6f7374792e76657263656c2e6170702f6170693f7265706f5f75726c3d68747470733a2f2f6769746875622e636f6d2f6d6f652d6d697a72616b2f7472616e73616374696f6e2d6275696c646572)](https://reboosty-reboosty.vercel.app/api?repo_url=https://github.com/moe-mizrak/transaction-builder)A lightweight fluent wrapper around Laravel `DB::transaction()` with support for retries, on-failure callbacks, and result access.

This package was created after [onFailureCallback PR](https://github.com/laravel/framework/pull/55338) which is rejected since it has a breaking change, so I've created `transaction-builder` package which provides `onFailureCallback` feature and even more can be added.

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

[](#installation)

```
composer require moe-mizrak/transaction-builder
```

Methods
-------

[](#methods)

- `make()`: Create a new instance of the TransactionBuilder.
- `attempts(int $attempts)`: The number of attempts to run the transaction. - default is 1.
- `run(callable $callback)`: The callback to be executed within the transaction.
- `onFailure(callable $callback)`: The callback to be executed if the transaction fails after all attempts.
- `disableThrow()`: Disable throwing exceptions on failure. - default is false (meaning that exceptions will be thrown as usual).
- `result()`: Get the result of the transaction. If the transaction fails, it will return null if `disableThrow()` is called, or throw an exception otherwise.

Usage
-----

[](#usage)

```
$result = TransactionBuilder::make()
    ->attempts(3) // number of attempts
    ->run(function () {
        // your transaction logic
        return 'done';
    })
    ->result();
```

### On Failure Callback

[](#on-failure-callback)

```
$result = TransactionBuilder::make()
    ->run(function () {
        throw new \Exception("fail");
    })
    ->onFailure(function ($exception) {
        logger()->error($exception->getMessage());
    })
    ->disableThrow() // optional if you want to disable throwing exceptions since you already have onFailure callback
    ->result();
```

### Nested Transactions

[](#nested-transactions)

```
$result = TransactionBuilder::make()
    ->run(function () {
        // outer transaction logic

        TransactionBuilder::make()
            ->attempts(2) // number of attempts
            ->run(function () {
                // inner transaction logic
            })
            ->onFailure(function ($exception) {
                logger()->error($exception->getMessage());
            })
            ->result();
    })
    ->result();
```

You can also do this:

```
$result = TransactionBuilder::make()
    ->run(function () {
        // outer transaction logic

        DB::transaction(function () {
            // inner transaction logic
        });
    })
    ->result();
```

💫 Contributing
--------------

[](#-contributing)

> **Your contributions are welcome!** If you'd like to improve this package, simply create a pull request with your changes. Your efforts help enhance its functionality and documentation.

> If you find this package useful, please consider ⭐ it to show your support!

📜 License
---------

[](#-license)

Transaction Builder for Laravel is an open-sourced software licensed under the **[MIT license](LICENSE)**.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance49

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

389d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/178c884a892aaf6813e8af8e2cb685bc987a168d9a0ebe9336455a795247ff96?d=identicon)[moe-mizrak](/maintainers/moe-mizrak)

---

Top Contributors

[![moe-mizrak](https://avatars.githubusercontent.com/u/12977885?v=4)](https://github.com/moe-mizrak "moe-mizrak (11 commits)")

---

Tags

laraveldatabasetransactionMoe Mizrakdatabase transactiontransaction-builderlaravel-transaction-builderTransactionBuilderchainable transaction

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/moe-mizrak-transaction-builder/health.svg)

```
[![Health](https://phpackages.com/badges/moe-mizrak-transaction-builder/health.svg)](https://phpackages.com/packages/moe-mizrak-transaction-builder)
```

###  Alternatives

[mvanduijker/laravel-transactional-model-events

Add eloquent model events fired after a transaction is committed or rolled back

75164.5k](/packages/mvanduijker-laravel-transactional-model-events)[nunomaduro/laravel-optimize-database

Publishes migrations that make your database production ready.

26123.0k](/packages/nunomaduro-laravel-optimize-database)[hpolthof/laravel-translations-db

A database translations implementation for Laravel 5.

545.8k](/packages/hpolthof-laravel-translations-db)[cubettech/lacassa

Cassandra based query builder for laravel.

358.5k](/packages/cubettech-lacassa)

PHPackages © 2026

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