mardi 27 octobre 2015

Lavary Menu from Model relationship

I'm building a laravel store with the following models (in that hierarchy) (this is just an example, don't mind the example terms):

  • Brand (eg. Chevrolet, VW, Ford) - hasMany(Sector)
  • Sector (eg. Hard work, City use, First Car) - hasMany(Family)
  • Family (eg. Suvs, Compact, Sub Compact) - hasMany(Product)
  • Product (eg. Bora, Focus, Camaro)

Now I want to create a Menu/Submenu using those models. I am using Lavary Menu in a middleware. I have this:

\Menu::make('MainNavigation', function($menu){
        $brands = Brand::all();

        foreach ($brands as $brand) {
            $menu->add($brand->name,array('action'=>['BrandsController@show','id' => $brand->id]));
        }
    });

Which displays the brand menu, its working ok. But I'd like to get the Sector of each Brand, and the Family of each Sector and add it to the correspondent menu.

Any advice would be very appreciated.

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire