Anonymous Migrations

The Laravel team released Laravel 8.37 with anonymous migration support, which solves a GitHub issue with migration class name collisions. The core of the problem is that if multiple migrations have the same class name, it'll cause issues when trying to recreate the database from scratch. Here's an example from the pull request tests:

1use Illuminate\Database\Migrations\Migration;
2use Illuminate\Database\Schema\Blueprint;
3use Illuminate\Support\Facades\Schema;
4 
5return new class extends Migration {
6 public function up(
7 {
8 Schema::table('people', function (Blueprint $table) {
9 $table->string('first_name')->nullable();
10 });
11 }
12 
13 public function down()
14 {
15 Schema::table('people', function (Blueprint $table) {
16 $table->dropColumn('first_name');
17 });
18 }
19};

Tip given by @nicksdot

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord