noouh/auto-model-fillable
最新稳定版本:v2
Composer 安装命令:
composer require noouh/auto-model-fillable
包简介
A Laravel package to auto-generate Fillable to models from table definitions.
README 文档
README
A Laravel package to auto-generate fillable properties for models based on table definitions from a JSON file.
Installation
You can install the package via composer:
composer require noouh/auto-model-fillable
Usage
To generate fillable properties for all models based on table definitions from a JSON file, use the following command:
php artisan noouh:generate-fillable path/to/your/json/file.json
Example JSON File
The JSON file should contain the table definitions with the columns. Here is an example structure:
[
{
"table": "users",
"columns": [
{
"name": "id",
"type": "int",
"primaryKey": true,
"autoIncrement": true
},
{ "name": "name", "type": "string" },
{ "name": "email", "type": "string" }
]
},
{
"table": "posts",
"columns": [
{
"name": "id",
"type": "int",
"primaryKey": true,
"autoIncrement": true
},
{ "name": "title", "type": "string" },
{ "name": "content", "type": "text" },
{ "name": "user_id", "type": "unsignedBigInteger" }
],
"relationships": [
{ "type": "belongsTo", "relatedTable": "users", "foreignKey": "user_id" }
]
}
]
How It Works
- Loop Through Model Files: The script loops through all model files in the
app/Modelsdirectory. - Extract Table Name: It extracts the table name from each model file using the
$tableproperty. - Get Columns from JSON: It retrieves the columns for the corresponding table from the provided JSON file.
- Update Fillable Properties: It updates the model file with the fillable properties if the table and columns are found.
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.
Email: info@noouh.com
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-22