How to add a column using after method in migration

How to add a column using after method in migration

How to add a column using the after method in migration, is a way to add new columns after a specific column. In this article, we will discuss adding a new column in a table using the after method in the migration file. Laravel migration files allow you to manage database tables structure like adding columns, removing columns and changing columns name, and much more.

How to add a column using after method in migration

Laravel version V8.27.0 introduced a new method in the migration file that allows us to add one or multiple new columns after columns. Here is the worked example of how to add a column using the after method in the migration file.

Schema::table('posts', function ($table) {
     $table->after('author', function ($table) {
        $table->string('post_category');
        $table->string('post_keywords');
        $table->string('post_desc');
     });
});

Comments

No Comment posted Yet!

Leave a Reply

OK! You can skip this field.