mylesduncanking / laravel-simple-migration
Streamlined class for simple migrations within Laravel
Requires
- php: >=7.3
- illuminate/database: >=8.0
- illuminate/support: >=8.0
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0|^7.0
README
📦 Installation
composer require mylesduncanking/laravel-simple-migration
❓ Why Use This Package?
Laravel's migrations are powerful but can become verbose and repetitive, especially for simple table structures or frequent seed/migrate workflows.
Laravel Simple Migration helps you:
- Write cleaner, array-based migration definitions
- Avoid boilerplate like
->after()
and->index()
- Automatically run seeders alongside migrations
- Maintain clarity and control with a minimal syntax layer
Perfect for rapid prototyping, internal tools, or any dev who loves less noise and more flow.
🚀 Getting Started
This package builds on Laravel's native migration system. If you're familiar with Laravel migrations, this will feel familiar.
To create a simple migration:
php artisan make:simple-migration your_migration_name
Your migration file will contain a $migration
array for defining schema changes.
Format
protected array $migration = [ 'TABLE_NAME' => [ 'COLUMN_NAME' => ['MODIFIERS'], // Additional columns... ], // Additional tables... ];
🔁 Auto-After Functionality
To save time when adding multiple columns, this package adds them sequentially by default. This removes the need for ->after('column')
.
To disable this:
php artisan vendor:publish --tag=simplemigration
Then set config/simplemigration.php > auto_after
to false
.
⚡ Auto-Index Functionality
By default, any column ending in _id
will automatically get an ->index()
modifier.
Customize this behavior:
php artisan vendor:publish --tag=simplemigration
Then edit the regex rules in config/simplemigration.php > auto_index
.
To exclude a specific column from auto-indexing, add noIndex
in its modifiers array.
🌱 Seeder Functionality
Table creations or updates often require seeders. This package uses Laravel's migration tracking to automatically run seeders during the up()
method.
This package assumes that seeders are stored under \Seeds
namespace and have a class name that starts with a capital letter and ends with Seeder
.
protected array $seeders = [ 'roles', // This will translate to (new \Seeds\RolesSeeder())->run() ];
Note: Seeders only run during
up()
by default. To run seeders during rollback (down()
), usebeforeDown()
orafterDown()
and callrunSeeder($seederName)
manually.
📘 Table Naming Convention
If a table includes an id
or uuid
column, it is assumed to be a new table. Otherwise, the table is assumed to be updated.
To explicitly define the action, use:
create:table_name
update:table_name
Or adjust assumptions globally:
config/simplemigration.php > type_assumptions
Example
protected array $migration = [ 'table_to_be_created' => [ 'id', 'name', 'date:dob' => ['nullable'], 'timestamps', ], 'table_to_be_updated' => [ 'name' => ['after:id'] ], 'create:pivot_table' => [ 'foreignId:key_1' => ['index'], 'foreignId:key_2' => ['index'], ], ];
🏷️ Column Key Format
Format keys as {type}:{column}
.
Examples:
integer:quantity
set:status
foreignId:user_id
date:dob
=> ['nullable']
✅ Supported Modifiers
You can use all default Laravel column modifiers in array format:
nullable
default:value
unique
index
after:other_column
comment:some text
noIndex
(custom)
✨ Helper Methods
beforeDown()
Hook to perform actions before the down()
method runs.
afterDown()
Hook to perform actions after the down()
method runs.
runSeeder($seeder)
Run a seeder manually.
✏️ Example Seeder Triggered in Migration
protected array $migration = [ 'roles' => [ 'id', 'name', ], ]; protected array $seeders = [ 'Role' ];
This will run RoleSeeder
when the migration is applied.
📁 Config File
To customize assumptions and toggles:
php artisan vendor:publish --tag=simplemigration
Edit config/simplemigration.php
to:
- Enable/disable auto-index or auto-after
- Add custom regex rules
- Set type assumptions for new vs update