theupriser / laravel-migration-extensions
Laravel migration extensions
Requires
- php: ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4
- illuminate/support: ^9.0 || ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
- phpunit/phpunit: ^9.0 || ^10.0 || ^11.0 || ^12.0
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
- Implement
Conditional
interface in yourSeeder
class.return new class extends Migration implements Conditional
- Add
seeders
from method stub, add seeders you want to run to the arraypublic function condition(): bool { return true; // or return false if you don't want it to run. }
- 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
- Implement
Seedable
interface in yourSeeder
class.return new class extends Migration implements Seedable
- Add
seeders
from method stub, add seeders you want to run to the arraypublic function seeders(): array { return [ \Database\Seeders\DatabaseSeeder::class, ]; }
- Run
php artisan migrate