Skip to content

Advanced usage

Every flag on this page is also documented in the generated Command options reference.

The primary key can be uuid or id. Use --primary-key=[uuid|id], or answer the interactive question.

Terminal window
php artisan make:event-sourcing-domain Animal --primary-key=id

Aggregates can be generated only when the primary key is uuid. Use --aggregate=[0|1], or answer the interactive question.

Terminal window
php artisan make:event-sourcing-domain Animal --aggregate=1 --primary-key=uuid

When aggregates are generated, actions automatically use them.

Read more about aggregates in Spatie’s documentation.

Use --reactor=[0|1].

Terminal window
php artisan make:event-sourcing-domain Animal --reactor=1

Reactors are generated for all events, including failed ones when enabled with --failed-events=1.

Read more about reactors in Spatie’s documentation.

The command can generate create / update / delete failed events. Use --failed-events=[0|1].

Terminal window
php artisan make:event-sourcing-domain Animal --failed-events=1

The following events are created:

AnimalCreationFailed
AnimalDeletionFailed
AnimalUpdateFailed

If notifications are also created with --notifications, a failed notification for each failed event is created automatically.

The command supports four types of notifications:

  • database
  • mail
  • Slack
  • Teams

Use --notifications=[database,mail,slack,teams], comma-separated. When notifications are created, one or more concerns (traits) are also created in the Notifications/Concerns folder for shared properties and formatting.

Terminal window
# database notifications
php artisan make:event-sourcing-domain Animal --notifications=database
# Teams notifications
php artisan make:event-sourcing-domain Animal --notifications=teams
# mail and Slack notifications
php artisan make:event-sourcing-domain Animal --notifications=mail,slack

The default indentation of generated files is 4 spaces. Use --indentation=NUMBER.

Terminal window
php artisan make:event-sourcing-domain Animal --indentation=2

This uses 2 spaces as indentation.

You can specify the app folder — for example when a domain must be created in a tests folder or in a package (root src). The default root folder is app. Use --root=VALUE.

Generate a domain in the src folder for a package

Section titled “Generate a domain in the src folder for a package”
Terminal window
php artisan make:event-sourcing-domain Animal --root=src
src/
├── Domain/
│ └── Animal/
│ ├── Actions/
│ │ ├── CreateAnimal
│ │ ├── DeleteAnimal
│ │ └── UpdateAnimal
│ ├── Aggregates/
│ │ └── AnimalAggregate
│ ├── DataTransferObjects/
│ │ └── AnimalData
│ ├── Events/
│ │ ├── AnimalCreated
│ │ ├── AnimalDeleted
│ │ └── AnimalUpdated
│ ├── Projections/
│ │ └── Animal
│ ├── Projectors/
│ │ └── AnimalProjector
│ └── Reactors/
│ └── AnimalReactor
└── etc.

Generate a domain in the tests/Unit folder

Section titled “Generate a domain in the tests/Unit folder”
Terminal window
php artisan make:event-sourcing-domain Animal --root=tests/Unit
tests/
└── Unit/
├── Domain/
│ └── Animal/
│ ├── Actions/
│ │ ├── CreateAnimal
│ │ ├── DeleteAnimal
│ │ └── UpdateAnimal
│ ├── Aggregates/
│ │ └── AnimalAggregate
│ ├── DataTransferObjects/
│ │ └── AnimalData
│ ├── Events/
│ │ ├── AnimalCreated
│ │ ├── AnimalDeleted
│ │ └── AnimalUpdated
│ ├── Projections/
│ │ └── Animal
│ ├── Projectors/
│ │ └── AnimalProjector
│ └── Reactors/
│ └── AnimalReactor
└── etc.