How to Add a New Column in Laravel

Adding a new column to an existing table in Laravel is something we do constantly as product requirements jump around. Running an SQL script directly against your database might be faster in the moment, but skipping migrations always ends up causing environment drift and deployment headaches.

Let's say we need to add a paid column to our users table.

Here's the standard way to do it:

  1. Generate the Migration: From your project root, run:

    php artisan make:migration add_paid_to_users_table --table=users
    

    Passing --table=users tells Artisan to spit out the boilerplate for modifying an existing table rather than creating a new one.

  2. Define the Schema Change: Open the generated file in database/migrations. Update the up method with your new column:

    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->integer('paid')->default(0); 
            // Or boolean('paid')->default(false)
        });
    }
    

    Always remember to define the down method so you can easily roll back if things go wrong:

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('paid');
        });
    }
    
  3. Run the Migration: Apply the change:

    php artisan migrate
    

Pro Tip: If it bothers you to append new columns at the very end of the table, you can slot them exactly where you want them using ->after(). It doesn't actually affect database performance, but the table reads cleaner:

$table->integer('paid')->default(0)->after('email');