Support the ongoing development of Laravel.io →
Database Eloquent Blade
Last updated 2 years ago.
0

When you var_dump($data) in the view, does it contain an array submenus?

0

sisou said:

When you var_dump($data) in the view, does it contain an array submenus?

Yes, here is the output of the var_dump: http://laravel.io/bin/xK0Bv

0

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.

0

Thank you, that was the sollution seems that the model returns a Collection of Objects which I though was just an ordinary array.

0

But When I want to use unlimited Sub menu, This way worked perfectly?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.