<?php
use Illuminate¥Database¥Migrations¥Migration;
use Illuminate¥Database¥Schema¥Blueprint;
use Illuminate¥Support¥Facades¥Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tags', function (Blueprint $table) {
$table->char('tag_category_id', 26)->after('name')->comment('タグカテゴリID');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tags', function (Blueprint $table) {
$table->dropColumn('tag_category_id');
});
}
};
bashでマイグレーションを実行する
php artisan migrate
LaravelのマイグレーションでMySQLの指定フィールドにindexを適応する
use Illuminate¥Support¥Facades¥Schema;
use Illuminate¥Database¥Schema¥Blueprint;
use Illuminate¥Database¥Migrations¥Migration;
class CreateAudiencesFriendsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('audiences_friends', function (Blueprint $table) {
// テーブルのカラムを定義
$table->char('audience_id', 26);
$table->string('friend_line_user_id', 255);
$table->timestamps();
// audience_id にインデックスを適用
$table->index('audience_id');
// friend_line_user_id にインデックスを適用
$table->index('friend_line_user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('audiences_friends');
}
}