Skip to content

Domain and namespace

A domain has the following structure:

app/
├── <Namespace>/
│ └── <Domain>/
│ ├── Actions/
│ │ ├── Create<Model>
│ │ ├── Delete<Model>
│ │ └── etc.
│ └── etc.
└── etc.

By default, the namespace (or root folder) is Domain. The name of the domain can be the same as the model, or different.

For model Animal:

app/
├── Domain/
│ └── Animal/
│ ├── Actions/
│ │ ├── CreateAnimal
│ │ ├── DeleteAnimal
│ │ └── etc.
│ └── etc.
└── etc.

Specify a different domain name with the --domain option (or answer the interactive question). This lets several models share the same domain.

Terminal window
php artisan make:event-sourcing-domain Tiger
Which is the name of the domain? [Tiger]
> Animal
Terminal window
php artisan make:event-sourcing-domain Lion
Which is the name of the domain? [Lion]
> Animal
Terminal window
php artisan make:event-sourcing-domain Animal --domain=Tiger
php artisan make:event-sourcing-domain Animal --domain=Lion

When specified as an option, the domain name is not asked.

Both approaches produce:

app/
├── Domain/
│ └── Animal/
│ ├── Actions/
│ │ ├── CreateLion
│ │ ├── CreateTiger
│ │ ├── DeleteLion
│ │ ├── DeleteTiger
│ │ └── etc.
│ └── etc.
└── etc.

Use the --namespace option to change the namespace:

Terminal window
php artisan make:event-sourcing-domain Tiger --namespace=MyDomain --domain=Animal

Result:

app/
├── MyDomain/
│ └── Animal/
│ ├── Actions/
│ │ ├── CreateTiger
│ │ ├── DeleteTiger
│ │ └── etc.
│ └── etc.
└── etc.

Reserved PHP words cannot be used as a namespace or domain.

Terminal window
php artisan make:event-sourcing-domain Tiger --namespace=Array --domain=Animal
ERROR The namespace Array is reserved by PHP.
Terminal window
php artisan make:event-sourcing-domain Tiger --domain=Echo
ERROR The domain Echo is reserved by PHP.