Laravel Migrations: Columns

Creating Columns

Schema::table('users', function (Blueprint $table) {
    $table->string('email');
});

Column Modifiers

Schema::table('users', function (Blueprint $table) {
    $table->string('email')->nullable();
});

In addition to the column types listed above, there are several column "modifiers" you may use while adding a column to a database table.

  • ->after('column').
  • ->autoIncrement().
  • ->charset('utf8').
  • ->collation('utf8_unicode_ci').
  • ->comment('my comment').
  • ->default($value).
  • ->first().
  • ->nullable($value = true).
  • ->storedAs($expression).
  • ->unsigned().
  • ->useCurrent().
  • ->virtualAs($expression).

Modifying Columns

Dropping Columns

Schema::table('users', function (Blueprint $table) {
    $table->dropColumn('votes');
});
Schema::table('users', function (Blueprint $table) {
    $table->dropColumn(['votes', 'avatar', 'location']);
});

Laravel Migrations: Columns — Structure map

Clickable & Draggable!

Laravel Migrations: Columns — Related pages: