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.
Read Also : Laravel collection macro
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']); }); } }