Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

onursagir's avatar

Migration from different folder.

Hello everybody,

I have encountered a small problem whilst experimenting with Laravel. Lets say that I have a migration:

/somefolder/migration/the_migration_itself.php

When I run:

php artisan migrate --path somefolder/migration/

It works right, not a single problem, but what ends up happening is I cant then run for example:

php artisan migrate:rollback

I get an error:

 [ErrorException]                                         
  Undefined index: the_migration_itself

I think this might have something to do with the way it gets stored in the database it just puts the_migration_itself in the migration column instead of maybe the entire path (somefolder/migration/the_migration_itself).

0 likes
9 replies
bugsysha's avatar

I always create Service Providers and with them register custom folder for migrations. Have you tried that?

1 like
onursagir's avatar

@bugsysha Hey man, I am not very experienced in Laravel atm, could you describe it a little bit more ?

Regardless, this should really work straight out of the box right? especially when considering the --path is standard option.

ohffs's avatar
ohffs
Best Answer
Level 50

There is also a --path option on the migrate:rollback - does that work?

3 likes
onursagir's avatar

@ohffs Oh I see yes it works now, I'm making a modular application so I have migrations all over the place I think I have to write a command to loop trough all the modules and roll them all back regardless, thank you very much

1 like
ohffs's avatar

No worries - glad it helped :-)

MarathonStudios's avatar

You can use loadMigrationsFrom() in your AppServiceProvider.

Inside the boot() function, run:

/**
 * Register Custom Migration Paths
 */
$this->loadMigrationsFrom([
    database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'folder1',
    database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'folder2',
]);/
3 likes
tourdev's avatar

Yes it does work. I've used it before. The syntax is this: php artisan migrate:rollback --path=/path/to/your/migrations/my_migration.php

bpjuli22's avatar

We can create the migrations in a particular directory that is inside a migrations like /database/migrations/newLocation by changing the path inside vendor/laravel/framework/src/Database/Migrations/MigrationCreater.php >> here:: inside getPath function => change the $path locations to new one like

return $path.'/tenant/'.$this->getDatePrefix().'_'.$name.'.php';

Please or to participate in this conversation.