Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

David Carr
David Carr

Posted on • Originally published atdcblog.dev on

     

Laravel organise migrations into folders

When a project grows the migrations folder can contain a lot of migration, ever wanted to desperate them into folders? turns out it's easy to so. All you need to do is tell Laravel where to read the migrations from.

In your AppServiceProvider.php boot call, you can call$this->loadMigrationsFrom() and give it a path of all the folder locations:

$migrationsPath=database_path('migrations');$directories=glob($migrationsPath.'/*',GLOB_ONLYDIR);$paths=array_merge([$migrationsPath],$directories);$this->loadMigrationsFrom($paths);
Enter fullscreen modeExit fullscreen mode

Now when you run

phpartisanmigrate
Enter fullscreen modeExit fullscreen mode

all folders will be scanned.

To migrate specific folders use --path for example for all migration in a folder called posts

phpartisanmigrate--path=/database/migrations/posts
Enter fullscreen modeExit fullscreen mode

or to make migration in a folder:

phpartisanmake:migrationcreate_posts_table--path=/database/migrations/posts
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

For the past 18 years, I've been developing applications using mostly PHP. I love to write tutorials and get involved with the community.
  • Location
    Hull, East Yorkshire, England
  • Education
    Degree
  • Joined

More fromDavid Carr

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp