Add columns to existing tables using migrate

Creates another file name and specifies it targets already created table named “posts”:

php artisan make:migration add_is_admin_column_to_posts_table --table="posts"

Inside your up function add a new column to this table like so:

$table->integer('is_admin')->unsigned();

In your down function make sure to drop the column as well:

$table->dropColumn('is_admin');

Then add this column to database by adding this to terminal:

php artisan migrate

Check phpmyadmin to see new column

Leave a Reply

Your email address will not be published.