blue-twilight/database/migrations/2017_09_10_080152_create_ph...

49 lines
1.1 KiB
PHP

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePhotoLabelsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('labels', function ($table) {
$table->increments('id');
$table->string('name');
$table->string('url_alias');
$table->timestamps();
});
Schema::create('photo_labels', function ($table) {
$table->unsignedBigInteger('photo_id');
$table->unsignedInteger('label_id');
$table->foreign('photo_id')
->references('id')->on('photos')
->onDelete('cascade');
$table->foreign('label_id')
->references('id')->on('labels')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('photo_labels');
Schema::dropIfExists('labels');
}
}