laravel 5.2迁移在特定列之前或之后添加列/字段


laravel 5.2 migration add column/field before or after specific column

我知道如何将列/字段添加到数据库中,例如

<?php
use Illuminate'Database'Schema'Blueprint;
use Illuminate'Database'Migrations'Migration;
class AddStatusToPhoto extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('photos', function(Blueprint $table)
        {
            $table->integer('status');
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }

}

但它会附加到表的最后一个字段,但我想添加到特定的列,例如在created_at之后插入字段,可以这样做吗?

如果您在MySQL上,可以使用after修饰符。

$table->integer('status')->after('created_at');

->after('column')将列"放在"另一列之后(仅MySQL)

Laravel文档-迁移-创建列-列修改器