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

what you need is a recursive function, basically a function that calls itself as soon as a child contains an submenu

example: http://www.lornajane.net/posts/2012/php-recursive-function-example-factorial-numbers

Last updated 2 years ago.
0

maybe instead of writing this yourself you can use Baum (https://github.com/etrepat/baum)

Last updated 2 years ago.
0

Thanks for responding, what would the recursive function look like? Do you have some sort of example?

Last updated 2 years ago.
0

It would look like the one you posted above. It works but is not very efficient, so either you cache it or you use a workaround such as Nested Sets (see the Baum package above) or Closure Table.

Last updated 2 years ago.
0

zenry said:

what you need is a recursive function, basically a function that calls itself as soon as a child contains an submenu

example: http://www.lornajane.net/posts/2012/php-recursive-function-example-factorial-numbers

His example is already recursive, it is calling the same function inside (self::createSubmenu).

Last updated 2 years ago.
0

barryvdh said:

zenry said:

what you need is a recursive function, basically a function that calls itself as soon as a child contains an submenu

example: http://www.lornajane.net/posts/2012/php-recursive-function-example-factorial-numbers

His example is already recursive, it is calling the same function inside (self::createSubmenu).

ah yes, quite right mr Barry, her example is already a recursive function

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lorienhd lorienhd Joined 20 Mar 2014

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.