PHPackages                             azmolla/transaction-middleware - 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. azmolla/transaction-middleware

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

azmolla/transaction-middleware
==============================

A Laravel middleware package that wraps DELETE requests in a DB transaction also a provides trait and class to call methods in a database transaction.

1.0.6(1y ago)06MITPHPPHP ^8.0

Since Feb 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/AbiruzzamanMolla/transaction-middleware-laravel)[ Packagist](https://packagist.org/packages/azmolla/transaction-middleware)[ Docs](https://github.com/AbiruzzamanMolla/transaction-middleware-laravel)[ RSS](/packages/azmolla-transaction-middleware/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (1)Versions (8)Used By (0)

Transaction Middleware for Laravel
==================================

[](#transaction-middleware-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5a8264bb32b362e9f1665e517d8d2f600135c6f5fded574f5ede14bc7824ba6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f417a6d6f6c6c612f7472616e73616374696f6e2d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/azmolla/transaction-middleware)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)

Transaction Middleware for Laravel is a simple package that provides a middleware to wrap DELETE requests in a database transaction. This means that if an error occurs during a DELETE request, any database changes will be rolled back automatically, ensuring data integrity.

**Version:** 1.0.6

---

Features
--------

[](#features)

- **DB Transaction on DELETE Requests:**Wraps only DELETE method requests in a database transaction. If an exception is thrown during request processing, the transaction is rolled back.
- **Flexible Auto-application:**Control how the middleware is applied via configuration:

    - `auto_apply_global` — Apply automatically to global middleware.
    - `auto_apply_web` — Apply automatically to the **web** group only.
    - `auto_apply_api` — Apply automatically to the **api** group only.
- **Manual Attachment:**Even if you choose not to auto-apply, the middleware is available via its alias (`transaction`) for manual attachment on routes.
- **Laravel Auto-Discovery:**The package uses Laravel’s auto-discovery so you don’t need to manually register the service provider.

---

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

[](#requirements)

- PHP ^8.0
- Laravel 9.x, 10.x, 11.x or 12.x (or higher)

---

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

[](#installation)

Install via Composer:

```
composer require azmolla/transaction-middleware
```

Laravel will automatically discover the service provider. If you need to publish the configuration file, run:

```
php artisan vendor:publish --tag=transaction-middleware-config
```

This will copy the configuration file to your Laravel application’s `config` directory as `transaction-middleware.php`.

---

Configuration
-------------

[](#configuration)

The published config file (`config/transaction-middleware.php`) looks like this:

```
