Skip to content

Instantly share code, notes, and snippets.

@abrahamfast
Forked from JeffreyWay/migration.php
Created April 28, 2016 06:19
Show Gist options
  • Save abrahamfast/8a2c87381b112696151fe703cd394984 to your computer and use it in GitHub Desktop.
Save abrahamfast/8a2c87381b112696151fe703cd394984 to your computer and use it in GitHub Desktop.
What else would you want on a typical pivot table...say for posts and tags.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class PivotPostTagTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('post_tag', function(Blueprint $table) {
$table->integer('post_id')->unsigned()->index();
$table->integer('tag_id')->unsigned()->index();
$table->foreign('post_id')->references('id')->on('post')->onDelete('cascade');
$table->foreign('tag_id')->references('id')->on('tag')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('post_tag');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment