noouh / auto-model-fillable
A Laravel package to auto-generate Fillable to models from table definitions.
v2
2024-07-22 10:25 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0|^9.0|^10.0
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/Models
directory. - Extract Table Name: It extracts the table name from each model file using the
$table
property. - 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