Bitte Ich möchte Getreide holen, basierend auf seiner category id
, wird sich freuen, wenn dieseFetch Aufzeichnungen basieren auf früheren ID - Laravel
Display-Seite
<div class="cat-list">
<h3 class="cat-title">
<a href="/filterByCategory/{{$category->cat_id}}">
<i class="fa fa-car ln-shadow"></i>
{{$category->cat_name}}<span class="count">{{$category->count()}}</span>
</a>
<span data-target=".cat-id-1" data-toggle="collapse" class="btn-cat-collapsed collapsed">
<span class=" icon-down-open-big"></span>
</span>
</h3>
<ul class="cat-collapse collapse in cat-id-1">
@php
$catID = $category->cat_id;
//want to fetch crops base on the $catID and display in foreach
@endphp
</ul>
</div>
Reglerfunktion
public function index()
{
$categories = Category::all();
$crops = Crop::all();
return view('public.index' , compact('categories' , 'crops'));
}
Crop Modell
public function category()
{
return $this->belongsTo(Category::class, 'cat_id', 'crop_cat')
}
Kategorie Model
public function category()
{
return $this->hasmany(Category::class, 'crop_cat','cat_id')
}
Sie haben noch nicht erläutert, wie eine Zuschneidung mit einer Kategorie zusammenhängt. Veröffentlichen Sie Ihre Datenbankschema- und/oder Modellbeziehungen. – fubar