定制 ronasit/laravel-entity-generator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ronasit/laravel-entity-generator

Composer 安装命令:

composer require ronasit/laravel-entity-generator

包简介

Provided console command for generating entities.

README 文档

README

Coverage Status

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:

  1. --only-entity, generate stack of classes to work with entity only inside the app, it includes:
  • migration
  • model
  • service
  • repository
  1. --only-api, generate stack of classes to implement API part to work with already existed entity:
  • routes
  • controller
  • requests
  • resources
  • tests

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:

  • C create
  • U update
  • D delete
  • R read (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 我们能提供哪些服务?
定制开发 / 二次开发

基于 ronasit/laravel-entity-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 52.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 5
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-10