LaravelPackages.net
Acme Inc.
Toggle sidebar
wmgbit/laravel-models-migration

Put Laravel migration definitions inside models, and keep them synchronized with the database

41
0
v1.0.0
About wmgbit/laravel-models-migration

wmgbit/laravel-models-migration is a Laravel package for put laravel migration definitions inside models, and keep them synchronized with the database. It currently has 0 GitHub stars and 41 downloads on Packagist (latest version v1.0.0). Install it with composer require wmgbit/laravel-models-migration. Discover more Laravel packages by wmgbit or browse all Laravel packages to compare alternatives.

Last updated

Laravel models migration

Put Laravel migration definitions inside models, and keep them synchronized with the database

Installation

composer require wmgbit/laravel-models-migration

Inside the model class

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;

class ModelExample extends Model 
{

    function migration(Blueprint $table)
    {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->foreignId('user_id')->constrained();
        $table->unique(['name','user_id']);
        $table->rememberToken();
        $table->timestamps();
    }

}

Command

Run the given command to run the laravel core migration script plus the definitions found in model classes againt the database

php artisan migrate:models

Limits

The command will keep the columns data if their names are the same. However, there is no way implemented to rename a given column. So changing a column name will be simply a REMOVE plus ADD task for that given column. May be added in future release.

Execution order

The command detects and handles the dependencies between models based on the definition of the foreign key constraints

Credit

This package is a fork from Laravel Automatic Migrations

Comments