amohamed / laravelmodelmaker
LaravelModelMaker 是一个功能强大且易于使用的 Laravel 开发者包...
v1.0.0
2023-05-06 17:14 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0
This package is auto-updated.
Last update: 2024-09-09 13:11:47 UTC
README
Laravel Model Maker 是一个简化 Laravel 项目中生成模型、迁移和关系的包。它提供了一套 artisan 命令,可以在单个命令中创建带有相应迁移和关系的模型。
功能
- 生成模型及其相应的迁移。
- 在模型之间创建关系(hasOne, hasMany, belongsTo 和 belongsToMany)。
- 使用简单语法的 artisan 命令易于使用。
安装
要安装 Laravel Model Maker 包,请使用以下 composer 命令
composer require amohamed/laravelmodelmaker --dev
建议仅将包用于开发。
使用方法
要生成模型及其迁移,请使用 generate-model
命令
php artisan atm:generate-model ModelName --fields="name:string:nullable,age:integer:unsigned:default(18),email:string:unique"
此命令将在 app 目录中创建名为 ModelName
的模型,并在数据库/migrations 目录中创建其对应的迁移。迁移将包含名称和年龄 字段
。
生成关系
要为现有模型生成关系,请使用 atm:generate-relationship 命令
php artisan atm:generate-relationship
此命令将提示您选择所需的关系和相关模型。
示例
可用选项和标志
$ php artisan atm:generate-model Post --fields="title:string,description:string:nullable,user_id:foreignId" Model name ................................................................................................................... Post Fields ................................................................... title:string, description:string:nullable, user_id:foreignId Model and migration created successfully. Would you like to generate relationships for this model? (yes/no) [no]: > yes Available relationship options: 1 => hasMany 2 => belongsTo 3 => hasOne 4 => belongsToMany Select the relationships you want to generate for this model. You can specify multiple relationships by separating them with a comma. > 1,2 Enter the related model for the 'hasMany' relationship: > Comment Enter the related model for the 'belongsTo' relationship: > User Relationships generated successfully.
贡献
欢迎贡献、问题报告和功能请求!请随意提交问题或创建拉取请求。
许可证
本包根据 MIT 许可证 发布。