9

i know how to add column/field to to database for example

<?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()
    {
        //
    }


}

but it will append to the last field of the table, but i want to add to specific column e.g insert the field after created_at, is it possible to do that?

hkguile
  • 4,235
  • 17
  • 68
  • 139
  • 1
    Possible duplicate of [Add sql table column before or after specific other column - by migrations in Laravel 4.1](http://stackoverflow.com/questions/20982538/add-sql-table-column-before-or-after-specific-other-column-by-migrations-in-la) – Tibrogargan May 13 '16 at 03:30

1 Answers1

12

There is a after modifier you can use if you are on MySQL.

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

->after('column') Place the column "after" another column (MySQL Only)

Laravel Docs - Migrations - Creating Columns - Column Modifiers

lagbox
  • 48,571
  • 8
  • 72
  • 83