Guest User

Untitled

a guest
Jun 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public function categories()
  2. {
  3. return $this->belongsTo(Category::class);
  4. }
  5.  
  6. public function items() {
  7. return $this->belongsTo(Item::class);
  8. }
  9.  
  10. public function getItems()
  11. {
  12.  
  13. $items = Item::with('categories')->get()->groupBy('category_id');
  14.  
  15. return view('home',compact('items'));
  16. }
  17.  
  18. public function getItems()
  19. {
  20. $items = Item::all()->groupBy('category_id');
  21. return view('home',compact('items'));
  22. }
  23. @foreach($items as $category_id => $categoryItems)
  24. {{ $category_id }}
  25. @foreach($categoryItems as $item)
  26. <!-- Item Details-->
  27. @endforeach
  28. @endforeach
Add Comment
Please, Sign In to add comment