Relation
Model relation is declared by using class traits and applied on the model itself.
Generating a new relationโ
You could run php artisan pandawa:make:relation to generate a base relation.
tip
Read more about CLI.
Or, use the namespace at Pandawa\Component\Ddd\RelationshipBehaviorTrait.
Template ๐
Replace the things encapsulated with <> including itself as well.
<?php
declare(strict_types=1);
namespace <Namespace>\<Folder>\Relation;
use Pandawa\Component\Ddd\Relationship\BelongsTo;
use Pandawa\Component\Ddd\RelationshipBehaviorTrait;
trait BelongsTo<Who> {
use RelationshipBehaviorTrait;
//->
}
Using the Relationshipโ
Go to the model you want to apply the relationship to and use the relation trait.
Example ๐งช
// ...
class Post extends AbstractModel {
use BelongsToUser;
}