Skip to content

Instantly share code, notes, and snippets.

@artemrogov
Created June 18, 2018 15:16
Show Gist options
  • Save artemrogov/7b8f1a012f15348754e19338098be9e4 to your computer and use it in GitHub Desktop.
Save artemrogov/7b8f1a012f15348754e19338098be9e4 to your computer and use it in GitHub Desktop.
ManyToMany RelationShips Products vs CategoryProducts
class CreateTbPivotCatProducts extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products_has_categories', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products');
$table->integer('category_product_id')->unsigned();
$table->foreign('category_product_id')->references('id')->on('category_products');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products_has_categories');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment