Add sql table column before or after specific other column - by migrations in Laravel 4.1

Lajdák Marek picture Lajdák Marek · Jan 7, 2014 · Viewed 60.7k times · Source

Table 'users':

|id|name|address|post_code|deleted_at|created_at|

and I want add column 'phone_nr' somewhere between 'id' and 'deleted_at'

Is it possible by migrations in Laravel 4.1?

Answer

James Binford picture James Binford · Jan 7, 2014

Yes. Create a new migration using php artisan migrate:make update_users_table.

Then use the table command as follows (if you're using MySQL!):

Schema::table('users', function($table)
{
    $table->string('phone_nr')->after('id');
});

Once you've finished your migration, save it and run it using php artisan migrate and your table will be updated.

Documentation: https://laravel.com/docs/4.2/migrations#column-modifiers