How to specify folder for laravel migrations? How to specify folder for laravel migrations? laravel laravel

How to specify folder for laravel migrations?


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/directoryphp artisan migrate --path=/path/to/your/migration/directory


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


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.