-
app/Models/Recipe.php
Open in GitHubuse 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 GitHubuse 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'); }); } // }