ronasit/laravel-entity-generator
Composer 安装命令:
composer require ronasit/laravel-entity-generator
包简介
Provided console command for generating entities.
README 文档
README
Laravel-Entity-Generator - This generator is used to create a standard class stack for a new entity.
Installation
Install package using dev mode
composer require ronasit/laravel-entity-generator --dev
Publish package's resources.
php artisan vendor:publish --provider="RonasIT\EntityGenerator\EntityGeneratorServiceProvider"
Usage
Entity generation
Call make:entity artisan command to run the generation command for the full stack of the entity classes:
php artisan make:entity Post
Entity name may contain the subfolder, in this case generated model and nova resource will be placed to
the subfolder as well:
php artisan make:entity Forum/Blog/Post
Fields definition options
The make:entity provides an ability to set the entity's fields, which will be used in all created classes (e.g. Model, Create/Update requests, Test fixtures, etc.)
php artisan make:entity Post -s title -s text -t published_at
The following field types are available to use:
| Type | Short Option | Full Option |
|---|---|---|
integer |
-i |
--integer |
float |
-f |
--float |
string |
-s |
--string |
boolean |
-b |
--boolean |
datetime |
-t |
--timestamp |
json |
-j |
--json |
Fields modifiers
To set a special behavior for the field use the modifiers syntax. Modifiers may be passed using a : symbol in the field definition. Multiple modifiers can be combined with a comma.
php artisan make:entity Post -s title:required,unique -s text -t published_at:required
Each modifier has full and short syntax. The list of available modifiers defined in the table:
| Modifier | Short syntax | Description |
|---|---|---|
required |
r |
Disallow to set null as a field value. Add required validation rule for creation, filled validation for the update, and not null in migration |
unique |
u |
Add a unique index in migration and unique validation rule for creation and update |
Reserved field names
The following field names are reserved and cannot be passed as input fields because they are managed automatically by Laravel and the generator:
| Field | Reason |
|---|---|
id |
Primary key, added by Laravel automatically |
created_at |
Timestamp, managed by Eloquent |
updated_at |
Timestamp, managed by Eloquent |
Relations definitions options
Command also provides an ability to set relations, which will be added to the model
php artisan make:entity Post -A Comment -A Reaction
Relation may be placed in the subfolder, in this case - set the relative namespace from the model directory:
php artisan make:entity Post -A Blog/Comment -A Forum/Common/Reaction
The following options are available to set relations:
| Type | Short Option | Full Option |
|---|---|---|
| Has one | -a |
--has-one |
| Has many | -A |
--has-many |
| Belongs to | -e |
--belongs-to |
| Belongs to many | -E |
--belongs-to-many |
Single class generation mode options
Command allows to generate only single entity-related class
php artisan make:entity Post --only-tests
The following options are available:
--only-model--only-repository--only-service--only-controller--only-requests--only-migration--only-factory--only-tests--only-seeder--only-resource--only-nova-tests
Mode combination options
Sometimes you need to generate the stack of classes to work with some entity only inside the application without the ability to manipulate it using API, or you need to create only API for already existed entity.
For this task, there are two mutually exclusive options:
--only-entity, generate stack of classes to work with entity only inside the app, it includes:
migrationmodelservicerepository
--only-api, generate stack of classes to implement API part to work with already existed entity:
routescontrollerrequestsresourcestests
Methods setting options
By default, the command generate all methods from the CRUD stack which includes:
- create
- update
- delete
- search
- get by id
But what if we need to create the interface only for updating and reading the entity? Just use the methods option for it:
php artisan make:entity Post --methods=RU
Feel free to use any combinations of actions in any order. Each action has its own character:
CcreateUupdateDdeleteRread (search and get by id)
Special class-related options
--nova-resource-name- Specifies the Nova resource name for the Nova tests generation. By default script will try to find the common resource class based on the entity name.
Release notes
1.3
Since 1.3 version you need to add to your config/entity-generator.php following data:
'paths' => [ ... // your old data 'database_seeder' => 'database/seeds/DatabaseSeeder.php', 'translations' => 'lang/en/validation.php' ], 'stubs' => [ ... // your old data 'empty_factory' => 'entity-generator::empty_factory', 'translation_not_found' => 'entity-generator::translation_not_found', 'validation' => 'entity-generator::validation', 'seeder' => 'entity-generator::seeder', 'database_empty_seeder' => 'entity-generator::database_empty_seeder' ]
ronasit/laravel-entity-generator 适用场景与选型建议
ronasit/laravel-entity-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52.84k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2017 年 04 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「entity generator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ronasit/laravel-entity-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ronasit/laravel-entity-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ronasit/laravel-entity-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Runn Me! Value Objects Library
generates php entities from openapi spec
DCSDynamicDiscriminatorMapBundle simplifies the use of Doctrine Single Table Inheritance mapping strategy in Symfony2.
swoft 2.0 entity creater
PhpPlaisio: Core Entity Lock
统计信息
- 总下载量: 52.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-10