niraj / crudstarter

自动化清洁仪表板的包。

7.4.1 2024-08-01 03:38 UTC

README

crudstarter_small

CRUD和API生成器包

Stars Issues License Packagist Packagist Downloads

允许您自动化的CRUD操作包。

详细包文档

GO TO DOCS

要求

Laravel Version: >= 8.0
PHP Version: >= 7.3
Composer: >= 2.0

安装

composer require niraj/crudstarter --dev

必需(发布配置文件)

php artisan vendor:publish --tag=crudstarter-config

可选(如果您想编辑占位符文件)

php artisan vendor:publish --tag=crud-stub

生成仪表板(一次性命令)

php artisan gen:dashboard

包使用

基本用法

  • 生成CRUD

php artisan gen:crud {模型名} --fields="字段名:数据类型 字段名:数据类型"

  • 生成API

php artisan gen:api {模型名} --fields="字段名:数据类型 字段名:数据类型

  • 删除CRUD文件

php artisan del:crud {模型名}

  • 删除API文件

php artisan del:api {模型名}

示例:生成Post CRUD php artisan gen:crud Post --fields="name:str slug:str description:text image:str status:bool"

添加字段

您可以在gen命令中添加字段,它将自动填充model, migration, request 和 api resources

要添加字段,我们使用 --fields="字段名1:数据类型1{空格}字段名2:数据类型2"

示例:生成带有字段的Post CRUD

php artisan gen:crud Post --fields="name:str description:text count:int by_admin:bool is_published:select:options=published,pending"

注意:请在您的ide/text-editor中运行自动对齐(代码格式化)命令在生成的blade文件中[例如:在phpstorm中 Ctrl+Alt+Shift+L].

添加关系

要添加此功能,只需在gen命令中添加 --relations="你的代码在这里"

示例:生成带有关系的Profile CRUD (hasOne: Account, hasMany: Blogs and belongTo: User)

php artisan gen:crud Profile --fields="name:str user_id:fid" --relations="haso:account hasm:blogs belt:user"

注意:如果您感到舒适,可以直接在 --relations 命令中使用 hasManybelongsTo 等,目前它仅支持这四种常见关系类型。

添加软删除功能

要添加此功能,只需在gen命令中添加 --softDelete

示例:生成带有软删除的Post CRUD

php artisan gen:crud Post --fields="name:str description:text" --softDelete

字段数据类型

提供了一些方便的简写,例如,在定义字段时,我们可以用 uint 代替 unsignedInteger,而不是使用其他数据类型如 date, enum, decimal, uuid 等。

注意:对于其他数据类型,如 date, enum, decimal, uuid 等,可以按原样输入。

将会生成什么!

  • CRUD

    -[模型、控制器、Blade文件、请求、迁移] 以及 功能测试骨架!

  • API

    -[ApiController、ApiRequest、ApiResource] 以及 功能测试骨架!

注意:如果需要,也可以为API生成模型、工厂和迁移。

自定义

  • 您可以通过简单地更改位于resources/crud-stub文件夹中的stub文件来轻松地将一切自定义到您的需求。

备注

  • 您可能需要轻松地根据您的仪表板模板自定义blade文件。这很容易做到。

  • 愉快的编码 🤘