Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muzammal01/syncmodelfillable
A Laravel package that automatically syncs a model's $fillable fields with its corresponding database migration columns by uisng simple Artisan command.
https://github.com/muzammal01/syncmodelfillable
artisan database fillable laravel laravel-10 laravel-11 laravel-8 laravel-9 laravel-development laravel-package migration model package php sync
Last synced: about 1 month ago
JSON representation
A Laravel package that automatically syncs a model's $fillable fields with its corresponding database migration columns by uisng simple Artisan command.
- Host: GitHub
- URL: https://github.com/muzammal01/syncmodelfillable
- Owner: Muzammal01
- Created: 2024-11-07T12:47:23.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-12-16T15:56:29.000Z (about 2 months ago)
- Last Synced: 2024-12-30T06:13:59.378Z (about 1 month ago)
- Topics: artisan, database, fillable, laravel, laravel-10, laravel-11, laravel-8, laravel-9, laravel-development, laravel-package, migration, model, package, php, sync
- Language: PHP
- Homepage:
- Size: 34.2 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SyncModelFillable
[![Latest Version on Packagist](https://img.shields.io/packagist/v/muzammal/syncmodelfillable.svg?style=flat-square)](https://packagist.org/packages/muzammal/syncmodelfillable)
[![Total Downloads](https://img.shields.io/packagist/dt/muzammal/syncmodelfillable.svg?style=flat-square)](https://packagist.org/packages/muzammal/syncmodelfillable)**SyncModelFillable** is a Laravel package designed to help automatically sync a model's `$fillable` fields with its database migration columns. π With just a simple Artisan command, you can keep your model properties up-to-date with your migration files effortlessly.
## β¨ Features
- π οΈ Syncs model `$fillable` properties with migration columns.
- π¦ Supports Laravel versions 8, 9, 10, and 11.
- βοΈ Customizable to exclude specific columns, like timestamps.
- π **New**: Added a `--ignore` flag to exclude specific models during sync.---
## π Installation
1. **Install the package via Composer:**
```bash
composer require muzammal/syncmodelfillable
```2. **(Optional) Publish the configuration file:**
If you'd like to customize which columns are excluded from the `$fillable` fields, publish the configuration file:
```bash
php artisan vendor:publish --provider="Muzammal\Syncmodelfillable\SyncModelFillableServiceProvider"
```This will create a `config/syncfillable.php` file where you can specify columns to exclude (such as `created_at`, `updated_at`, `deleted_at` etc.).
---
## π Usage
This package provides an Artisan command `sync:fillable` that lets you sync a model's `$fillable` fields with its migration columns.
### Sync a Specific Model's `$fillable` Fields
To sync the `$fillable` fields of a specific model, use the command with the model name. For example, if you have a model named `Post`:
```bash
php artisan sync:fillable Post
```This will:
- Look for the `Post` model in the `app/Models` directory.
- Find the migration file associated with the modelβs database table.
- Update the `$fillable` property in the model with the columns from the migration file.### Sync All Models in `app/Models`
To sync all models in the `app/Models` directory, use `all` as the parameter:
```bash
php artisan sync:fillable all
```This will:
- Look for all models in the `app/Models` directory.
- Match each model with its migration file.
- Update the `$fillable` property for each model.### **New**: Exclude Models with the `--ignore` Flag
You can now exclude specific models from the sync operation using the `--ignore` flag. For example:
```bash
php artisan sync:fillable all --ignore=User
```This will sync all models except `User`. You can also pass multiple models to ignore:
```bash
php artisan sync:fillable all --ignore=User,Product,Order
```If you want to run the sync for a single model, ignoring doesn't apply here:
```bash
php artisan sync:fillable Product
```### **How It Works**
- The `--ignore` flag allows you to pass a comma-separated list of model names to exclude during the sync process.
- If a model is listed in the ignore list, it will be skipped during the sync.---
## βοΈ Configuration
The configuration file `syncfillable.php` allows you to specify which columns to exclude from the `$fillable` fields. By default, common timestamp columns (`created_at`, `updated_at`, `deleted_at`) are excluded.
**Example configuration:**
```php
return [
'excluded_columns' => ['created_at', 'updated_at', 'deleted_at'],
];
```Add any column names here that you want to exclude from the `$fillable` fields.
---
## π Example
Suppose you have a `Post` model with a migration that defines columns such as `name`, `slug`, and `content`. Running the following command:
```bash
php artisan sync:fillable Post
```Would automatically set the `$fillable` fields in `Post.php` as follows:
```php
protected $fillable = ['name', 'slug', 'content'];
```---
## π License
This package is open-source software licensed under the MIT license.