Laravel 9: Stub Migrations!

rezakhademix

Reza Khademi

Posted on January 18, 2022

Laravel 9: Stub Migrations!

Soon, Laravel 9 wil release and there are some new features that we can use them.

This series is going to be a sequel about Laravel framework version 9 and in each article we will review a new feature!

1. Laravel 9: Stub Migration

Since Laravel 8.37, there is no need to create a migration with a specific class name. If we have so many migrations and probably forgot about their class name or we are afraid to have collisions in new migration, this feature coming handy and nice.

According to the pull request on github this feature is backward compatible.

So how do we can create it?

Just run this command: php artisan make:migration and it will give you this:

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::table('users', function (Blueprint $table) {

            $table->string('nick_name')->nullable();
        });
    }
};

Enter fullscreen mode Exit fullscreen mode

It's an anonymous migration which will do any things to any model you decide, just you have no worries about class names anymore.

That's it... Any question?

💖 💪 🙅 🚩
rezakhademix
Reza Khademi

Posted on January 18, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Laravel 9: Stub Migrations!
laravel Laravel 9: Stub Migrations!

January 18, 2022