anhnguyen02/code-generator

Laravel CRUD 代码生成支持包。

v1.0.1 2023-10-09 04:16 UTC

This package is auto-updated.

Last update: 2024-09-10 10:31:35 UTC


README

要开始使用,你应该将 anhnguyen02/code-generator Composer 依赖项添加到你的项目中

composer require anhnguyen02/code-generator --dev

目前仅支持 laravel 10.x

用法

创建 CURD API

php artisan crud:api music MusicController --api --requests --middleware="['api']"

当你运行上述命令时,你将收到确认或提示进行下一步操作的帮助。或者,你也可以使用以下命令选项的组合来绕过对支持的需求。

创建控制器

php artisan crud:controller PostController --model=Post
选项
['api':  'Exclude the create and edit methods from the controller']
['type': 'Manually specify the controller stub file to use']
['force': 'Create the class even if the controller already exists']
['invokable': 'Generate a single method, invokable controller class']
['model': 'Generate a resource controller for the given model']
['parent': 'Generate a nested resource controller class']
['resource': 'Generate a resource controller class']
['requests': 'Generate FormRequest classes for store and update']
['singleton': 'Generate a singleton resource controller class']
['creatable': 'Indicate that a singleton resource should be creatable']

创建模型

php artisan crud:model Post --fillable="['title', 'body']"
选项
['all': 'Generate a migration classes for the model'],
['migration': 'Create a new migration file for the model'],
['soft-deletes': 'Enable soft deletes for a model'],
['has-uuids': 'Use a UUID key instead of an auto-incrementing integer key'],
['fillable': 'The names of the fillable columns'],
['pk': 'The name of the primary key'],
['relationships': 'The relationships for the model'],
['force': 'Overwrite model file content'],
# If you want to create migration
['schema': 'The name of the schema'],
['indexes': 'The fields to add an index to'],
['foreign-keys': 'Foreign keys'],

创建迁移

php artisan crud:migration posts --schema="title#string; body#text"
选项
['schema': 'The name of the schema'],
['indexes': 'The fields to add an index to'],
['foreign-keys': 'Foreign keys'],
['pk': 'The name of the primary key'],
['soft-deletes': 'Include soft deletes fields'],

迁移字段类型

  • 字符串
  • 字符
  • 变长字符串
  • 日期
  • 日期时间
  • 时间
  • 时间戳
  • 文本
  • 中长文本
  • 长文本
  • JSON
  • JSONB
  • 二进制
  • 整数
  • 大整数
  • 中整数
  • 小整数
  • 短整数
  • 布尔值
  • 十进制
  • 双精度
  • 浮点数
  • 枚举