Notice: Only for 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:
Schema::table('table', function (Blueprint $table) {
$table->string('column')->after('column');
});
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:
Schema::table('table', function (Blueprint $table) {
$table->string('column')->before('column_2');
});
If you want your column to be the first in your table , then use the first method.
Schema::table('table', function (Blueprint $table) {
$table->string('column')->first();
});
Also the after() method can now be used to add multiple fields.
Schema::table('table', function (Blueprint $table) {
$table->after('remember_token', function ($table){
$table->string('column_1')->nullable();
$table->string('column_2')->nullable();
});
});
Top comments (0)