When you var_dump($data)
in the view, does it contain an array submenus
?
sisou said:
When you
var_dump($data)
in the view, does it contain an arraysubmenus
?
Yes, here is the output of the var_dump: http://laravel.io/bin/xK0Bv
Hey,
Menu::with('submenus')->get();
Returns a Collection of Objects (Menu objects). Since you are defining a relationship in your Model like this
public function submenus()
{
return $this->hasMany('Submenu');
}
That's not returning a $key => $value array hence you can't iterate like you want to.
To be able to iterate through your relations you would do somethink like
@foreach ($data as $menu)
<li>{{ $menu->name }}</li>
@foreach($menu->submmenus as $submenu)
{{ $submenu->name }}
@endforeach
@endforeach
That should solve your issue.
Thank you, that was the sollution seems that the model returns a Collection of Objects which I though was just an ordinary array.
But When I want to use unlimited Sub menu, This way worked perfectly?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community