Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

app/Models/Recipe.php

Open in GitHub
use Illuminate\Database\Eloquent\Model;
 
class Recipe extends Model
{
//
public function ingredients()
{
return $this->belongsToMany(Ingredient::class)->withPivot('quantity');
}
//
}

resources/views/recipes/show.blade.php

Open in GitHub
// ...
 
@foreach ($recipe->ingredients as $ingredient)
<li class="dark:text-gray-200"">
{{ $ingredient->pivot->quantity }} {{ $ingredient->name }}
</li>
@endforeach
 
// ...

database/migrations/2020_12_03_150502_add_quantity_to_ingredient_meal_pivot_table.php

Open in GitHub
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
 
class AddQuantityToIngredientMealPivotTable extends Migration
{
public function up()
{
Schema::table('ingredient_meal', function (Blueprint $table) {
$table->string('quantity');
});
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.