Quick start
Generate a basic domain structure:
php artisan make:event-sourcing-domain Animal --domain=AnimalThis creates a complete event-sourced domain in app/Domain/Animal/Animal/.
What gets generated
Section titled “What gets generated”Always generated:
Actions/— Create / Update / Delete action classesDataTransferObjects/— DTOs for model dataEvents/— domain events (Created, Updated, Deleted)Projections/— the read model (Eloquent model)Projectors/— event handlers that update projections
Optional (with flags):
Aggregates/— aggregate root (--aggregate=1, requires a uuid primary key)Reactors/— side-effect handlers (--reactor=1)Notifications/— event notifications (--notifications=database,mail,slack,teams), plusNotifications/Concerns/shared traitstests/Domain/{Domain}/{Model}/— PHPUnit tests (--unit-test)
With failed events (--failed-events=1):
- Additional events:
{Model}CreationFailed,{Model}UpdateFailed,{Model}DeletionFailed - Corresponding notifications when
--notificationsis also set
Using the generated code
Section titled “Using the generated code”If Spatie event sourcing is configured to auto-discover projectors, the result is immediately usable:
use App\Domain\Animal\Actions\CreateAnimal;use App\Domain\Animal\DataTransferObjects\AnimalData;use App\Domain\Animal\Projections\Animal;
// Creates a record in the 'animals' table via the AnimalProjector(new CreateAnimal)(new AnimalData( name: 'tiger', age: 7));
// Retrieve it$animal = Animal::query()->where('name', 'tiger')->first();Where next
Section titled “Where next”- Basic usage — the interactive walkthrough
- Migrations — generate a domain from an existing migration
- Command options — every flag, generated from the command