Skip to content

Instantly share code, notes, and snippets.

@dmitrybubyakin
Created May 3, 2017 18:37
Show Gist options
  • Save dmitrybubyakin/988cf697dcf7f0e881f969e03b460edb to your computer and use it in GitHub Desktop.
Save dmitrybubyakin/988cf697dcf7f0e881f969e03b460edb to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateInterestsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
* @throws Exception
*/
public function up()
{
try {
Schema::create('interests', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 256)->unique();
$table->string('description', 512)->nullable();
});
Schema::create('interestables', function (Blueprint $table) {
$table->integer('interest_id')->unsigned();
$table->morphs('interestable');
$table->foreign('interest_id')->references('id')->on('interests')
->onDelete('cascade')
->onUpdate('cascade');
$table->primary(['interest_id', 'interestable_id', 'interestable_type'], 'interestables_pk');
});
} catch (\Exception $e) {
$this->down();
throw $e;
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('interestables');
Schema::dropIfExists('interests');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment