Skip to content

Commit

Permalink
Added ingredient meal relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinByrne committed Nov 24, 2020
1 parent e504e44 commit 033005f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/Models/Ingredient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class Ingredient extends Model
'name',
];

/**
* The meals that belong to the ingredient.
*/
public function meals()
{
return $this->belongsToMany('App\Models\Meal');
}

/**
* Get the url path for the Timing
*
Expand Down
8 changes: 8 additions & 0 deletions app/Models/Meal.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function timing()
return $this->belongsTo('App\Models\Timing');
}

/**
* The ingredients that belong to the meal.
*/
public function ingredients()
{
return $this->belongsToMany('App\Models\Ingredient');
}

/**
* Get the url path for the Meal
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateIngredientMealPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ingredient_meal', function (Blueprint $table) {
$table->foreignId('ingredient_id')->constrained()->onDelete('cascade');
$table->foreignId('meal_id')->constrained()->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ingredient_meal_pivot');
}
}

0 comments on commit 033005f

Please sign in to comment.