Last active
February 17, 2018 11:32
-
-
Save nextlevelshit/932e5ef7c927ecdbc390665e51724e20 to your computer and use it in GitHub Desktop.
Laravel 5 many-to-many migration table for belongsToMany() connections between two Entities. This is a so called pivot table two foreign keys, that create its index.
This file contains 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\Support\Facades\Schema; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateAuthorEntryTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('author_entry', function (Blueprint $table) { | |
$table->integer('author_id')->unsigned()->index(); | |
$table->foreign('author_id')->references('id') | |
->on('authors')->onDelete('cascade'); | |
$table->integer('entry_id')->unsigned()->index(); | |
$table->foreign('entry_id')->references('id') | |
->on('entries')->onDelete('cascade'); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('author_entry'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment