laravel

How to add a column using after method in migration

How-to-add-a-column-using-after-method-in-migration.png

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');
     });
});



About author

IMG_8897.png

Muhammad Zubair

My name is Muhammad Zubair. I'm a full-stack developer. I'm a owner of theskillstock.com. I love to write tutorials of PHP, Laravel, Html & css, Javascript, Java and much more with examples.


Comments

Hello World! https://apel.top/go/gu4winrshe5dgoju?hs=2fcc0d928e33a6133a3e036866ae4514& Mar 24th 2023

5dakrb



Leave a Reply