aesircloud/laravel-domains
Composer 安装命令:
composer require aesircloud/laravel-domains
包简介
A Laravel package for rapid domain driven development.
README 文档
README
A Laravel package to scaffold Domain-Driven Design (DDD) structures in your Laravel projects. This package creates a complete suite of files—domain entities, value objects, repositories, domain services, models (with optional soft deletes), factories, observers, policies, and even migrations—so you can quickly get started with a DDD approach.
FEATURES
-
Domain Scaffolding Automatically creates directories and stub files for a new domain.
-
Model Generation Generates a domain model extending your BaseModel with optional soft delete support.
-
Factory, Observer, & Policy Generates a factory, observer, and policy for your domain.
-
Optional Migrations Create migrations (with or without soft deletes) for your domain’s table.
-
Repository Binding Automatically updates your RepositoryServiceProvider with the new domain’s repository binding.
-
CRUD Actions Generates a full set of CRUD actions (Create, Update, Delete, Index, Show) using
aesircloud/laravel-actions. -
Optional Soft Delete Actions When the domain uses soft deletes, additional Restore and ForceDelete actions are generated.
-
Value Object Generation Use the make:value-object command to scaffold a new value object. Optionally specify a domain to place the value object within that domain’s folder.
-
Interactive Prompts If a file already exists, you'll be prompted (defaulting to replace) so you can control file overwrites.
-
--force Option Overwrite existing files without being prompted.
-
Customizable Stubs Publish the package stubs for customization.
INSTALLATION
Install the package via Composer:
composer require aesircloud/laravel-domains
Laravel’s package auto-discovery will register the service provider automatically. If you need to manually register it, add the following to your config/app.php providers array:
AesirCloud\LaravelDomains\Providers\DomainServiceProvider::class,
PUBLISHING STUBS
To customize the stub files used for scaffolding, publish the package stubs:
php artisan vendor:publish --tag=ddd-stubs
This will copy all stub files into stubs/laravel-domains in your project, where you can modify them as you wish.
USAGE
To scaffold a new domain, run the following command:
php artisan make:domain {DomainName} [--migration] [--soft-deletes] [--force]
HOW DOMAIN NAMING WORKS
- Class Names: DomainName is automatically converted to StudlyCase.
- Table Names: The table name is derived from your raw domain input, converted to snake_case and pluralized.
Example: php artisan make:domain user_profile
- Domain class name: UserProfile
- Table name: user_profiles
BASIC EXAMPLES
-
Basic Domain Creation
php artisan make:domain User
Creates domain files under
app/Domains/User/Generates a User model, factory, observer, policy, DTO, repository interface, and domain service. -
Domain with Migration
php artisan make:domain User --migration
Also creates a migration in the
database/migrationsfolder. -
Domain with Soft Deletes
php artisan make:domain User --soft-deletes
Model, observer, policy, repository, and actions will include soft-delete logic.
-
Domain with Migration and Soft Deletes
php artisan make:domain User --migration --soft-deletes
-
Force Overwrite of Existing Files
php artisan make:domain User --force
Automatically overwrites any existing files without prompting.
The command will:
- Create domain directories (e.g.,
app/Domains/User/Entities,Repositories,DomainServices). - Generate stub files for Entity, Repository Interface, and Domain Service.
- Create a BaseModel (if not already present) and a domain-specific model in
app/Models(using soft delete logic if selected). - Create a DTO file using spatie/laravel-data in
app/Domains/User/DataTransferObjects. - Create a factory in
database/factories. - Create an observer in
app/Observersand a policy inapp/Policies. - Optionally generate a migration file (using stubs from
stubs/model). - Update the RepositoryServiceProvider with the binding for the new domain’s repository interface and its concrete implementation.
- Generate CRUD actions (Create, Update, Delete, Index, Show), with optional Restore and ForceDelete actions if soft deletes are enabled.
MAKING A SUBDOMAIN
To create a subdomain within an existing domain, use the make:subdomain command:
php artisan make:subdomain {ParentDomain} {SubdomainName} [--migration] [--soft-deletes] [--force]
EXAMPLES
Example: Under the 'User' domain, create a 'AuthenticationLogs' subdomain
php artisan make:subdomain User AuthenticationLogs --migration --soft-deletes
- Also creates actions in app/Actions/{ParentDomain}/{SubdomainName}, e.g. app/Actions/User/AuthenticationLogs/DeleteAuthenticationLogAction.php.
- Binds the repository to RepositoryServiceProvider.
NOTE: The parent domain (e.g. app/Domains/User) must already exist before you can add a subdomain within it.
- You can make a folder in the
app/Domains/<domain>directory to represent a parent domain that you do not need to scaffold. E.g.,app/Domains/HumanResources. Then you can create subdomains within that folder. - Example:
php artisan make:subdomain HumanResources Payroll --migration --soft-deletes
MAKING A VALUE OBJECT
You can also generate a value object, optionally scoping it to a domain:
php artisan make:value-object Address
Creates a file named AddressValueObject.php in app/ValueObjects.
Or specify a domain:
php artisan make:value-object Address --domain=User
Or specify a domain and subdomain:
php and artisan make:value-object Check --domain=HumanResources --sub-domain=Payroll
You can also use the --force option to overwrite existing files:
php artisan make:value-object Address --force
REQUIREMENTS
- PHP: 8.3 or higher
- Laravel: 11.42 or higher
- illuminate/console: 11.42 or higher
- illuminate/support: 11.42.1 or higher
- spatie/laravel-data: 4.13 or higher
- aesircloud/sluggable: 1.1.0 or higher
- aesircloud/laravel-actions: 1.0.0 or higher
DESIGN AND DEVELOPMENT STANDARDS
Please see the Standards & Pattern Philosophy file for the design and development standards used in this package.
Security
If you've found a bug regarding security please mail security@aesircloud.com instead of using the issue tracker.
LICENSE
The MIT License (MIT). Please see License file for more information.
aesircloud/laravel-domains 适用场景与选型建议
aesircloud/laravel-domains 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「domain」 「Domain Driven Design」 「AesirCloud」 「laravel domains」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aesircloud/laravel-domains 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aesircloud/laravel-domains 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aesircloud/laravel-domains 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Package that provides an integration with Doctrine ORM to automatically dispatch Domain Events.
Domain Driven Design related Classes and Utilities
Build a domain-oriented application on Laravel Framework
Command bus implementation: Commands and domain events
A module manager for Zend Framework which can be used to create configs per domain.
DDD auth basic class
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-17