Skip to content

Commit

Permalink
HasDomainFactory trait implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperTey committed Mar 23, 2024
1 parent 051e631 commit b7e7b82
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ All notable changes to `laravel-ddd` will be documented in this file.

## [Unversioned]
### Added
- Config keys `ddd.domain_path` and `ddd.domain_namespace` added to specify path to the domain folder and root domain namespace. This allows a custom domain namespace if it differs from the basename of the domain path. e.g., `src/Domains` domain folder, but with `Domain` namespace.
- Add `ddd.domain_path` and `ddd.domain_namespace` to config, to specify the path to the domain layer and root domain namespace more explicitly (replaces the previous `ddd.paths.domains` config).
- Implement `Lunarstorm\LaravelDDD\Factories\HasDomainFactory` trait which can be used on domain models that are unable to extend the base domain model.

### Changed
- Default `base-model.php.stub` now utilizes the `HasDomainFactory` trait.

### Deprecated
- Config `ddd.paths.domains` deprecated in favour of `ddd.domain_path` and `ddd.domain_namespace`.
- Config `ddd.paths.domains` deprecated in favour of `ddd.domain_path` and `ddd.domain_namespace`. Existing config files published prior to this release should remove `ddd.paths.domains` and add `ddd.domain_path` and `ddd.domain_namespace` accordingly.

## [0.9.0] - 2024-03-11
### Changed
Expand Down
15 changes: 15 additions & 0 deletions src/Factories/HasDomainFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Lunarstorm\LaravelDDD\Factories;

use Illuminate\Database\Eloquent\Factories\HasFactory;

trait HasDomainFactory
{
use HasFactory;

protected static function newFactory()
{
return DomainFactory::factoryForModel(get_called_class());
}
}
10 changes: 2 additions & 8 deletions src/Models/DomainModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

namespace Lunarstorm\LaravelDDD\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Lunarstorm\LaravelDDD\Factories\DomainFactory;
use Lunarstorm\LaravelDDD\Factories\HasDomainFactory;

abstract class DomainModel extends Model
{
use HasFactory;
use HasDomainFactory;

protected $guarded = [];

protected static function newFactory()
{
return DomainFactory::factoryForModel(get_called_class());
}
}
10 changes: 2 additions & 8 deletions stubs/base-model.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

namespace {{ namespace }};

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Lunarstorm\LaravelDDD\Factories\DomainFactory;
use Lunarstorm\LaravelDDD\Factories\HasDomainFactory;
use Illuminate\Database\Eloquent\Model;

abstract class {{ class }} extends Model
{
use HasFactory;
use HasDomainFactory;

protected $guarded = [];

protected static function newFactory()
{
return DomainFactory::factoryForModel(get_called_class());
}
}

0 comments on commit b7e7b82

Please sign in to comment.