Laravel 9 Anonymous Migration Classes

All of the migration stubs do not have the traditional class names. Previous versions of laravel, the migration file was setup with the class name, for example:

class CreatePostsTable extends Migration
{


}

In Laravel 9 the migration file is setup as follows:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
};

Leave a Reply

Your email address will not be published.