44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
class CreateRecipeProductsTable extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up()
|
|
{
|
|
Schema::create('recipe_products', function (Blueprint $table) {
|
|
$table->integer('recipe_id')->unsigned();
|
|
$table->integer('product_id')->unsigned();
|
|
$table->integer('weight')->unsigned();
|
|
$table->foreign('recipe_id')
|
|
->references('id')
|
|
->on('recipes')
|
|
->onUpdate('cascade')
|
|
->onDelete('cascade');
|
|
$table->foreign('product_id')
|
|
->references('id')
|
|
->on('products')
|
|
->onUpdate('cascade')
|
|
->onDelete('cascade');
|
|
$table->primary(['recipe_id', 'product_id']);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down()
|
|
{
|
|
Schema::dropIfExists('recipe_products');
|
|
}
|
|
}
|