larexsetch/laravel-transactional

Decorates method as transactional

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/larexsetch/laravel-transactional

1.0.0 2026-01-28 13:11 UTC

This package is auto-updated.

Last update: 2026-01-28 13:12:48 UTC


README

Decorates method as transactional

Usage

Require dependency

composer require larexsetch/laravel-transactional

Append middleware

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->append(\Larexsetch\LaravelTransactional\Http\Middleware\TransactionalMiddleware::class);
    })
    ->create();

Add attribute in controller

readonly class NoteController
{
    public function __construct(
        private SomeService $service
    ) {}

    #[Transactional]
    public function index($request): JsonResponse
    {
        $this->service->doOne();
        $this->service->doAnother();
        // ... more actions

        return response()->json(['ok' => true]);
    }
}

Run tests

export DOCKER_TEST_TAG=phpunit:latest
docker build -t $DOCKER_TEST_TAG -f tests/Dockerfile .
docker run --rm -v ./:/opt/project $DOCKER_TEST_TAG /usr/local/bin/phpunit --configuration phpunit.xml tests/Http/Middleware