Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function categories()
- {
- return $this->belongsTo(Category::class);
- }
- public function items() {
- return $this->belongsTo(Item::class);
- }
- public function getItems()
- {
- $items = Item::with('categories')->get()->groupBy('category_id');
- return view('home',compact('items'));
- }
- public function getItems()
- {
- $items = Item::all()->groupBy('category_id');
- return view('home',compact('items'));
- }
- @foreach($items as $category_id => $categoryItems)
- {{ $category_id }}
- @foreach($categoryItems as $item)
- <!-- Item Details-->
- @endforeach
- @endforeach
Add Comment
Please, Sign In to add comment