How to make laravel update table migration

In this tutorial we will discuss how to make laravel update table migration. create a migration for add new column in laravel. dropColumn in update table migration.


Laravel add new column in table migration

First we create a new migration for creating a table and after want to add new columns in that table use laravel update table migration feature. This migration have two methods up() and down(). up() method add or change columns and down() use for rollback migration.

Update table migration command

Here we want to add profile, and status column in users table. run below command it create a new migration.

php artisan make:migration add_profile_in_users_table --table=users

New column add migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\Product;

class AddProfileUsersTable extends Migration
{

  public function up()
  {
    Schema::table('users', function($table) {
        $table->string('profile');
        $table->enum('status', [0, 1])->default(1);
    });
  }

  // rollback the migration
  public function down()
  {
    Schema::table('users', function($table) {
        $table->dropColumn(['profile', 'status']);
    });
  }
}

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links