How to add new column in existing table in Laravel migration?

Use the code below to add a new column in an existing table using Laravel migration.

php artisan make:migration add_paid_to_users_table --table=users
  
public function up()
{
    Schema::table('users', function($table) {
        $table->integer('paid');
    });
}

public function down()
{
    Schema::table('users', function($table) {
        $table->dropColumn('paid');
    });
}

php artisan migrate

Use Laravel migration add column after as shown below.

Schema::table('users', function ($table) {
    $table->string('email')->after('id')->nullable();
});

Or add new column in existing table in Laravel migration using the commands given below.

php artisan make:migration add_paid_to_users_table --table=users
php artisan make:migration add_profile_to_users

Leave a Comment