Laravel Custom Migration Paths

By default, migrations are stored in database/migrations/.You can organize them into subfolders for better structure:


Example Structure

database/migrations/

├── 2024_01_01_000000_create_users_table.php
├── blog/
│   └── 2024_02_01_000000_create_posts_table.php
├── shop/
│   └── 2024_02_02_000000_create_products_table.php


You can create these folders manually two folders blog and shop.Generate migrations into them using:

php artisan make:migration create_posts_table --path=database/migrations/blog

This generates a file in database/migrations/blog/:

public function up(): void
{
  Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('content');
    $table->timestamps();
  });
}

public function down(): void
{
  Schema::dropIfExists('posts');
}


Running Migrations:

php artisan migrate --path=database/migrations/blog


Rollback Comment

php artisan migrate:rollback --path=database/migrations/blog



Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.