app/Models/Recipe.php
use Illuminate\Database\Eloquent\Model; class Recipe extends Model{ // public function ingredients() { return $this->belongsToMany(Ingredient::class)->withPivot('quantity'); } //}
use Illuminate\Database\Eloquent\Model; class Recipe extends Model{ // public function ingredients() { return $this->belongsToMany(Ingredient::class)->withPivot('quantity'); } //}
// ... @foreach ($recipe->ingredients as $ingredient) <li class="dark:text-gray-200""> {{ $ingredient->pivot->quantity }} {{ $ingredient->name }} </li>@endforeach // ...
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'); }); } //}