Blog Detail Pic

Add New Column to Laravel Table With Migration

Avatar
by Kwilio | May 5, 2021

In this tutorial I will teach you how to add a new column using Laravel migration and Laravel Modules. This tutorial is specific to Laravel Modules but can easily be applied to Laravel core migration.

Steps:

1. Add a new migration with the following. Change to your module and column name

php artisan module:make-migration add_description_column_to_movie_table Movie

2. Open the new migration file and inside the up function add your new column

Schema::table('movies', function($table) {
        $table->text('description');
    });

3. Inside the down function, add the following code to remove your new column.

Schema::table('movies', function($table) {
        $table->dropColumn('description');
    });

4. Finally fun the following, again changing the module name to add your new column.

php artisan module:migrate Movie

That's it! Support our website if you would like more tutorials like this.