Put Laravel migration definitions inside models, and keep them synchronized with the database
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
Put Laravel migration definitions inside models, and keep them synchronized with the database
composer require wmgbit/laravel-models-migration
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();
}
}
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
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.
The command detects and handles the dependencies between models based on the definition of the foreign key constraints
This package is a fork from Laravel Automatic Migrations