Home > Blockchain >  Laravel - does migrate command work with folders?
Laravel - does migrate command work with folders?

Time:08-24

I've made a migration in a folder and when I run php artisan migrate nothing happens. I do not want to specify a certain folder every time to run migrations so I am not sure what the error is.

I do not see the migration in the migrations table. here are some outputs

php artisan make:migration create_<whatever>_table --path='/database/migrations/<MyFolderName>/'

   INFO  Created migration [2022_08_23_090654_create_<whatever>_table].

php artisan migrate

   INFO  Nothing to migrate.

php artisan migrate:status

  Migration name ............................................. Batch / Status
  2019_12_14_000001_create_personal_access_tokens_table ...... [6] Ran
  2021_09_01_145427_create_users_table ....................... [5] Ran
  2021_09_01_145441_create_<another1_table>_table ............ [5] Ran
  2021_09_01_145452_create_<another2_table>_table ............ [5] Ran
  2021_09_01_145927_create_<another3_table>_table ............ [6] Ran
  2021_09_01_150555_create_<another4_table>_table ............ [6] Ran

CodePudding user response:

If the additional paths you use are knowable beforehand you can add the following in one of your service providers (e.g. in AppServiceProvider):

app()->make('migrator')->path(database_path('migrations/<MyFolderName>/'));

This should make your migrator (the class that is responsible for running migrations) to also look in the given path for new migrations.

As @ODelibalta pointed out there is a method that can simplify this in the ServiceProvider class already:

$this->loadMigrationsFrom([database_path().'/migrations/<FolderName>']);

Running the above in any service provider should work and may be preferable because it deffers resolving the migrator until it's needed.

  • Related