How to specify folder for laravel migrations?

You might want to take a look at this package, it's not exactly what you are looking for but it is an alternative to sorting and organizing sections of your application including controller, migrations, models, views and others.

Nwidart's Laravel Modules for modular application development with Laravel,

It helps to organize your application into modules, and so, you can create migrations in each module, and since the modules are in separate folders it helps fix this issue someway.


If you eager to do this, here is a quick solution at nscreed/laravel-migration-paths pakcage. Very simple and easy to use.

During the periodical development phase the migrations folder may become very large. It is very helpful if we can organize the content of the migration folders. This library helps to organize migration files in different folders. Even, if your organize your existing files it will works as well.

Hope, it will help you.


In AppServiceProvider, find a boot method and add there following

$mainPath = database_path('migrations');
$directories = glob($mainPath . '/*' , GLOB_ONLYDIR);
$paths = array_merge([$mainPath], $directories);
         
$this->loadMigrationsFrom($paths);
         

Now you can use php artisan migrate and also php artisan migrate:back when having migrations in sub folders


When creating new migrations and executing your migrations, you can pass in a path parameter through the command line interface to specify the directory it will use to create and run the migrations respectively.

php artisan make:migration create_users_table --path=/path/to/your/migration/directory

php artisan migrate --path=/path/to/your/migration/directory