I am trying to put laravel database migrations in sub folders, but not sure how to do this.
-
2https://stackoverflow.com/questions/21641606/laravel-running-migrations-on-app-database-migrations-folder-recursively – ata Mar 06 '19 at 08:37
-
yes, migrate part is clear, but ii am concerned about make:migration – Veljko Sirovljević Mar 06 '19 at 08:40
-
Possible duplicate of [Laravel 5.6: Migration from a specific folder](https://stackoverflow.com/questions/52430179/laravel-5-6-migration-from-a-specific-folder) – dparoli Mar 06 '19 at 09:00
-
No @dparoli, i am interested in making migrations, not running them. – Veljko Sirovljević Mar 06 '19 at 09:01
-
2The argument is the same: `php artisan make:migration --path=/database/migrations/your_path` – dparoli Mar 06 '19 at 09:02
4 Answers
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

- 1,631
- 14
- 18
-
2an example to be precised: `php artisan make:migration create_users_table --path=database/migrations/v1/` – oussama benounnas Dec 23 '21 at 14:37
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

- 37,872
- 26
- 173
- 191
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.

- 867
- 8
- 7
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.

- 1,631
- 14
- 18

- 1,163
- 1
- 14
- 35