Add Column After A Column In Laravel Migration - TechvBlogs

Add Column After A Column In Laravel Migration

In this article, you will learn How To Add a Column After A Column In Laravel Migration.


Suresh Ramani - Author - TechvBlogs
Suresh Ramani
 

1 year ago

TechvBlogs - Google News

By adding new tables and columns. Laravel Migrations provide you the ability to manage the structure of your database. The Laravel Migrations act as database version control.

In this tutorial, We'll look at how to add one column at a time to the Laravel migration. It's probable that you'll need to add a new field to the database table once a project is completed. Creating a new migration in Laravel will make it straightforward to do so in that instance.

To make understanding easier, you should put that column after the relevant one. So let's look at the process.

Add Column After A Column In Laravel Migration

Laravel 8.27 introduces a new after method on the Blueprint migration instance which allows you to add multiple new columns after an existing column at the same time:

Schema::table('users', function ($table) {
     $table->after('password', function ($table) {
        $table->string('address_line1');
        $table->string('address_line2');
        $table->string('city');
     });
});

Thank you for reading this article.

Read Also: How To Install PHP 8.2 on Ubuntu 22.04

Comments (0)

Comment


Note: All Input Fields are required.