Skip to main content
  1. Packages/
  2. Diamond Console/

Domain

2 mins·

Introduction #

Domain Layer in Domain Driven Design is a layer that hold the whole of your business logic, so this layer like as heart of your application.

Commands #

The list of commands that can you use for structuring your Domain Driven Design project.

Action #

Command for generate an Action inside your Domain directory.

Command #

php artisan domain:make:action GenerateProfileAction User

Arguments #

NameDescription
NameAction class name
DomainDomain Name

Options #

NameDescription
--forceForce create the Action class

Builder #

Command for generate a Query Builder inside your Domain directory.

Command #

php artisan domain:make:builder UserBuilder User

Arguments #

NameDescription
NameBuilder class name
DomainDomain Name

Options #

NameDescription
--model=ModelNameTo hint Model class on Query Builder
--forceForce create the Builder class

Usage #

In your model you can use the builder like the example below.

src/Domain/Shared/User/Models/User.php

<?php

namespace Domain\Shared\User\Models;

use Domain\Shared\User\Models\Builders\UserBuilder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * @mixin  UserBuilder
 */
class User extends Model
{
    use HasFactory;

    /**
     * @param  $query
     *
     * @return UserBuilder<User>
     */
    public function newEloquentBuilder($query): UserBuilder
    {
        return new UserBuilder(query: $query);
    }
}

Enum #

Command for generate an Enum to your Domain directory.

Command #

php artisan domain:make:enum Role User

Arguments #

NameDescription
NameEnum class name
DomainDomain Name

Options #

NameDescription
--forceForce create the Enum class

Model #

Command for generate a Model inside Shared in Domain directory, all Model will store shared folder since another Domain probably consume the Model at the same time.

Command #

php artisan domain:make:model User User

Arguments #

NameDescription
NameModel class name
DomainDomain Name

Options #

NameDescription
-m or --migrationCreate Migration file when model created
-f or --factoryCreate Factory class when Model created this option will generate two files, Factory contract and Factory concrete
--forceForce create the Model class

Value Object #

Command for generate a Value Object class. This command will generate Value Object class into Domain.

Command #

php artisan domain:make:value-object ReferralCode User

Arguments #

NameDescription
NameValue Object name class
DomainDomain Name

Options #

NameDescription
--forceForce create the Value Object class