mardi 24 septembre 2019

How can i display grouped values in Laravel

I'm Trying to display restaurant Menus grouped by the categories, for example...

  • Lunch
    • Chicken and Chips
    • Rice
  • Breakfast
    • Tea
    • Coffee So I have 3 tables in my database, Restaurants, Categories, And Menus

Restaurants controller

public function show($slug, RestaurantRepository $repository){
      if(! $restaurant = $repository->get(['slug' => $slug], with(['cuisines','user', 'photos', 'thumbs', 'region', 'ratings.user']))) return abort('404');

      $menus=Menu::with(['category_type'])->where('restaurant_id',$restaurant->id)->get()->groupBy('category_id');

       return view('frontend.restaurant.show', compact('restaurant', 'p','menus'));
}

when i Dump this it looks just fine.

This is what is returned from the $menu variable

Results have been grouped

Expand results set with relationships

Now my trouble is on the View when i try to get results of this i get an error.

   @if($menus)
   <ul>
     @foreach($menus as $m)
       <li>
         
       </li>
     @endforeach
   </ul>
   @endif

ErrorException (E_ERROR).

Property [name] does not exist on this collection instance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire