Last active
April 28, 2016 06:19
-
-
Save JeffreyWay/6143691 to your computer and use it in GitHub Desktop.
What else would you want on a typical pivot table...say for posts and tags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
} |
That's is because I suggested it, I use to add it too, will be great has option! :)
I think I'm going to leave timestamps off for the time being. Takes two seconds to add it manually.
I know you said you were going to leave it off, but just for reference, I +1 the addition of timestamps
Could you make the foreign key constraints optional (default on is fine).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@montogeek timestamps it's more an user preference I think. I usually add it. I suggested @JeffreyWay that it could be an option.