hitocean / crud-generator
这是我的包 crud-generator
1.0.3
2024-06-24 00:25 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0||^11.0
- laravel/prompts: ^0.1.24
- nette/php-generator: ^4.1
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
This package is auto-updated.
Last update: 2024-09-15 14:19:43 UTC
README
安装
您可以通过 composer 安装此包
composer require hitocean/crud-generator
使用方法
模型配置
php artisan make:hit-model-config
此命令允许生成一个配置文件用于生成模型。此文件将位于 generators/models 目录中。
生成的文件如下所示。
{
"modelName": "Company",
"root_folder": "src/Domain/Company/Models",
"root_namespace": "Src\\Domain\\Company\\Models",
"tableName": "companies",
"crud": true,
"attributes": [
{
"name": "name",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "address",
"type": "?string"
}
]
}
在此文件中,您可以修改在生成模型文件之前的所有值。
创建模型
php artisan make:hit-model
此命令允许根据配置文件中的属性和关系生成模型。它将生成以下文件
- 模型
- 工厂
- 迁移
需要注意的是,在运行命令时,将尝试在 generators/models 目录内创建所有文件。如果模型已存在,它将尝试替换。
控制器配置
php artisan make:hit-controller-config
与模型类似,此命令创建一个配置文件,然后根据此文件创建控制器。此文件将创建在 generators/controllers 目录中。
注意事项
- 需要生成的控制器模型已经创建并迁移。
- 运行命令时,会要求选择要生成的 CRUD 方法,需要触摸空格键来标记。
生成的文件如下所示
{
"controller_name": "CompanyController",
"root_folder": "src/Application/Company/Controllers",
"root_namespace": "Src\\Application\\Company\\Controllers",
"model_import": "Src\\Domain\\Company\\Models\\Company",
"test_path": "tests/Application/Company/Controllers/CompanyControllerTest",
"methods": [
{
"name": "index",
"route_method": "get",
"data_class_import": null,
"data_class_path": null,
"resource_class_import": "Src\\Application\\Company\\Resources\\IndexCompanyResource",
"resource_class_path": "src/Application/Company/Resources/IndexCompanyResource",
"inputs": [],
"outputs": [
{
"name": "id",
"type": "int"
},
{
"name": "name",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "address",
"type": "string"
},
{
"name": "created_at",
"type": "date"
},
{
"name": "updated_at",
"type": "date"
}
]
},
{
"name": "store",
"route_method": "post",
"data_class_import": "Src\\Application\\Company\\Data\\StoreCompanyData",
"data_class_path": "src/Application/Company/Data/StoreCompanyData",
"resource_class_import": null,
"resource_class_path": null,
"inputs": [
{
"name": "id",
"type": "int"
},
{
"name": "name",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "address",
"type": "string"
},
{
"name": "created_at",
"type": "date"
},
{
"name": "updated_at",
"type": "date"
}
],
"outputs": []
},
{
"name": "update",
"route_method": "put",
"data_class_import": "Src\\Application\\Company\\Data\\UpdateCompanyData",
"data_class_path": "src/Application/Company/Data/UpdateCompanyData",
"resource_class_import": null,
"resource_class_path": null,
"inputs": [
{
"name": "id",
"type": "int"
},
{
"name": "name",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "address",
"type": "string"
},
{
"name": "created_at",
"type": "date"
},
{
"name": "updated_at",
"type": "date"
}
],
"outputs": []
},
{
"name": "destroy",
"route_method": "delete",
"data_class_import": null,
"data_class_path": null,
"resource_class_import": null,
"resource_class_path": null,
"inputs": [],
"outputs": []
},
{
"name": "show",
"route_method": "get",
"data_class_import": null,
"data_class_path": null,
"resource_class_import": "Src\\Application\\Company\\Resources\\ShowCompanyResource",
"resource_class_path": "src/Application/Company/Resources/ShowCompanyResource",
"inputs": [],
"outputs": [
{
"name": "id",
"type": "int"
},
{
"name": "name",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "address",
"type": "string"
},
{
"name": "created_at",
"type": "date"
},
{
"name": "updated_at",
"type": "date"
}
]
}
]
}
创建控制器
php artisan make:hit-controller
重要: 将在 generators/controllers 目录中创建所有控制器。如果已经存在,则将覆盖。
运行此命令将创建以下文件
- 控制器。
- 数据。
- 资源。
- 测试。
注意事项
- 需要在相应位置注册路由,该包不会自动完成。
- 生成的 UpdateData 不考虑传入的 route parameter,需要手动添加。例如:#[FromRouteParameter('company')]
- 控制器中的关系尚未考虑。
变更日志
有关最近更改的更多信息,请参阅 变更日志
贡献
有关详细信息,请参阅 贡献指南
安全漏洞
有关如何报告安全漏洞,请参阅 我们的安全策略
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件