How to add a new column to an existing table of laravel 9 in a migration
Jun 11, 2022
In this lesson we are going to learn how to add a column to an existing table on MYSQL DB on Laraval.
###Step 1
Run this command on your terminal on the root project directory.
php artisan make:migration add_paid_to_users_table --table=users
a migration will be created with **add_paid_to_users_table** name.
### Step 2
Edit this file with the column name you wish to add
// new column name is **paid**public function up()
{
Schema::table('users', function($table) {
$table->integer('paid');
});
}public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
### Step 3
Finally run
php artisan migrate
That’s it, when you check your table on MYSQL you should see the new column added.
Happy Coding!