Skip to content

CQBus MediatorClean architecture for Laravel

Decouple your commands, queries, and events with zero configuration. Auto-discovery, attribute routing, and pipelines โ€” out of the box.

Stop writing Fat Controllers.
Start writing Actions.

Decouple your business logic, routing, and side effects instantly.

The full CQRS flow โ€” in one Action class
php
// app/Http/Actions/RegisterUserAction.php

#[Api] // โšก Applies 'api' middleware group AND 'api/' prefix automatically
class RegisterUserAction
{
    use AsAction;

    public function __construct(private readonly Mediator $mediator) {}

    public static function route(Router $router): void
    {
        $router->post('/register');                    // POST /api/register
    }

    public function handle(RegisterUserRequest $request): JsonResponse
    {
        $user = $this->mediator->send($request);                       // โ†’ RegisterUserHandler
        $this->mediator->publish(new UserRegisteredEvent($user->id));  // โ†’ N notifications

        return response()->json($user, 201);
    }
}