Add column to table in Laravel


Create migration in console:

php artisan make:migration add_mycolumn_to_mytable
Bash

Use Schema::table() to access existing table (instead of Schema::create() for creating new tables)

public function up()
{
    Schema::table('mytable', function($table) {
        $table->text('mycolumn');
    });
}
public function down()
{
    Schema::table('mytable', function($table) {
        $table->dropColumn('mycolumn');
    });
}
PHP

Then run migrations:

php artisan migrate
Bash

Leave a Reply

Your email address will not be published. Required fields are marked *