diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e7c8b6..316a5ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,18 +2,28 @@ All notable changes to `laravel-ddd` will be documented in this file. -## [Unversioned] +## [0.7.0] - 2023-10-22 ### Added -- Formal support for subdomains (nested domains). For example, to generate model `Domain\Reporting\Internal\Models\InvoiceReport`, the domain argument can be specified in any of the following ways: - - `ddd:model Reporting\\Internal InvoiceReport` - - `ddd:model Reporting/Internal InvoiceReport` - - `ddd:model Reporting.Internal InvoiceReport` +- Formal support for subdomains (nested domains). For example, to generate model `Domain\Reporting\Internal\Models\InvoiceReport`, the domain argument can be specified with dot notation: `ddd:model Reporting.Internal InvoiceReport`. Specifying `Reporting/Internal` or `Reporting\\Internal` will also be accepted and normalized to dot notation internally. - Implement abstract `Lunarstorm\LaravelDDD\Factories\DomainFactory` extension of `Illuminate\Database\Eloquent\Factories\Factory`: - Implements `DomainFactory::resolveFactoryName()` to resolve the corresponding factory for a domain model. - Will resolve the correct factory if the model belongs to a subdomain; `Domain\Reporting\Internal\Models\InvoiceReport` will correctly resolve to `Database\Factories\Reporting\Internal\InvoiceReportFactory`. ### Changed -- Default base model implementation in `base-model.php.stub` now uses using `DomainFactory::factoryForModel()` inside the `newFactory` method to resolve the model factory. +- Default base model implementation in `base-model.php.stub` now uses `DomainFactory::factoryForModel()` inside the `newFactory` method to resolve the model factory. + +### BREAKING +- For existing installations of the package to support sub-domain model factories, the base model's `newFactory()` should be updated where applicable; see `base-model.php.stub`. +```php +use Lunarstorm\LaravelDDD\Factories\DomainFactory; + +// ... + +protected static function newFactory() +{ + return DomainFactory::factoryForModel(get_called_class()); +} +``` ## [0.6.1] - 2023-08-14 ### Fixed diff --git a/README.md b/README.md index 5921e7a..2ff78c1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Laravel-DDD is a toolkit to support domain driven design (DDD) patterns in Laravel applications. One of the pain points when adopting DDD is the inability to use Laravel's native `make:model` artisan command to properly generate domain models, since domain models are not intended to be stored in the `App/Models/*` namespace. This package aims to fill the gaps by providing an equivalent command, `ddd:model`, plus a few more. -> :warning: **Disclaimer**: While this package is publicly available for installation, it is subject to frequent design changes as it evolves towards a stable v1.0 release. It is currently being tested and fine tuned within Lunarstorm's client projects. +> :warning: **Disclaimer**: This package is subject to frequent design changes as it evolves towards a stable v1.0 release. It is currently being tested and fine tuned within Lunarstorm's client projects. ## Installation @@ -49,6 +49,7 @@ php artisan ddd:view-model {domain} {name} # Generates an action php artisan ddd:action {domain} {name} ``` + Examples: ```bash php artisan ddd:model Invoicing LineItem # Domain/Invoicing/Models/LineItem @@ -60,6 +61,14 @@ php artisan ddd:view-model Invoicing ShowInvoiceViewModel # Domain/Invoicing/Vie php artisan ddd:action Invoicing SendInvoiceToCustomer # Domain/Invoicing/Actions/SendInvoiceToCustomer ``` +Subdomains (nested domains) can be specified with dot notation: +```bash +php artisan ddd:model Invoicing.Customer CustomerInvoice # Domain/Invoicing/Customer/Models/CustomerInvoice +php artisan ddd:factory Invoicing.Customer CustomerInvoice # Database/Factories/Invoicing/Customer/CustomerInvoiceFactory +# Supported by all generator commands +``` +``` + This package ships with opinionated (but sensible) configuration defaults. If you need to customize, you may do so by publishing the config file and generator stubs as needed: ```bash