Create Column after Another Column

Notice: Only MySQL

If you're adding a new column to the existing table, it doesn't necessarily have to become the last in the list. You can specify after which column it should be created:

1Schema::table('users', function (Blueprint $table) {
2 $table->string('phone')->after('email');
3});

If you're adding a new column to the existing table, it doesn't necessarily have to become the last in the list. You can specify before which column it should be created:

1Schema::table('users', function (Blueprint $table) {
2 $table->string('phone')->before('created_at');
3});

If you want your column to be the first in your table , then use the first method.

1Schema::table('users', function (Blueprint $table) {
2 $table->string('uuid')->first();
3});

Also the after() method can now be used to add multiple fields.

1Schema::table('users', function (Blueprint $table) {
2 $table->after('remember_token', function ($table){
3 $table->string('card_brand')->nullable();
4 $table->string('card_last_four', 4)->nullable();
5 });
6});

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord