noouh/auto-model
最新稳定版本:v1.0.2
Composer 安装命令:
composer require noouh/auto-model
包简介
A Laravel package to auto-generate models and migrations from table definitions.
README 文档
README
A Laravel package to auto-generate models and migrations from table definitions.
About the Company
Noouh For Integrated Solutions is dedicated to providing innovative software solutions. We specialize in developing high-quality applications tailored to meet the specific needs of our clients.
Installation
To install the Noouh Auto Model package, you can require it using Composer:
composer require noouh/auto-model
Publish the Stubs
After installing the package, publish the stubs using the following command:
php artisan vendor:publish --tag=stubs
This will publish the model.stub and migration.stub files to your project's stubs directory.
Usage
Create a JSON file (e.g., tables.json) with your table definitions and relationships. Here is an example structure:
[
{
"table": "users",
"columns": [
{ "name": "name", "type": "string" },
{ "name": "email", "type": "string" }
]
},
{
"table": "posts",
"columns": [
{ "name": "title", "type": "string" },
{ "name": "content", "type": "text" },
{ "name": "user_id", "type": "unsignedBigInteger" }
],
"relationships": [
{ "type": "belongsTo", "relatedTable": "users", "foreignKey": "user_id" }
]
}
]
Run the command to generate models and migrations:
php artisan generate:models /path/to/tables.json
Example
Given the following tables.json file:
[
{
"table": "users",
"columns": [
{ "name": "name", "type": "string" },
{ "name": "email", "type": "string" }
]
},
{
"table": "posts",
"columns": [
{ "name": "title", "type": "string" },
{ "name": "content", "type": "text" },
{ "name": "user_id", "type": "unsignedBigInteger" }
],
"relationships": [
{ "type": "belongsTo", "relatedTable": "users", "foreignKey": "user_id" }
]
}
]
Running the command:
php artisan generate:models /path/to/tables.json
Will generate:
- A
Usermodel inapp/Models/User.php - A
Postmodel inapp/Models/Post.phpwith abelongsTorelationship to theUsermodel - A migration file for the
userstable - A migration file for the
poststable with a foreign key to theuserstable
License
This package is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-03