theupriser/laravel-migration-extensions

Laravel migration extensions

v1.2.0 2025-02-08 12:39 UTC

This package is not auto-updated.

Last update: 2025-03-09 11:10:24 UTC


README

This package contains a couple of extensions for the laravel migrator.

Installation

You can install the package via composer with the following steps:

Install the theupriser/laravel-migration-extensions package.

composer require theupriser/laravel-migration-extensions

Usage

Conditional

The Conditional Interface makes it possible to run migrations based on conditions in your application. Sometimes you don't need tables or columns if your application doesn't need them.

How to

  1. Implement Conditional interface in your Seeder class.
    return new class extends Migration implements Conditional 
    
  2. Add seeders from method stub, add seeders you want to run to the array
    public function condition(): bool
    {
     return true; // or return false if you don't want it to run.
    }
    
  3. Run php artisan migrate

Seedable

The Seedable Interface makes it possible to run seeders after the migration runs. Every unique seed added will be executed once after the migrations have run. This function exists because Tables can change and so do the columns in your tables. If seeders are added to an earlier migration they break and have to be deleted from the migrations to be runnable again. You constantly have to keep track.

This changes that! you add the seeders to the seeders method in the Seedable class and the migrator will keep track for you. It even checks if the Seeder still exists in your project.

How to

  1. Implement Seedable interface in your Seeder class.
    return new class extends Migration implements Seedable 
    
  2. Add seeders from method stub, add seeders you want to run to the array
    public function seeders(): array
    {
     return [
         \Database\Seeders\DatabaseSeeder::class,
     ];
    }
    
  3. Run php artisan migrate

Credits