DEV Community

David Carr
David Carr

Posted on • Originally published at dcblog.dev on

1

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 mode Exit fullscreen mode

Now when you run

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

all folders will be scanned.

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

php artisan migrate --path=/database/migrations/posts
Enter fullscreen mode Exit fullscreen mode

or to make migration in a folder:

php artisan make:migration create_posts_table --path=/database/migrations/posts
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs