How to create a multi-level menu with Adminlte Menu Runtime in Laravel?

Asked

Viewed 248 times

1

I joined the jeroennoten/Laravel-Adminlte to a project Laravel 5.7, however, I’m having difficulty generating a menu with multiple levels.

According to the reference in the project repository jeroennoten/Laravel-Adminlte, this would be the code to generate a runtime menu;

public function boot(Dispatcher $events)
{
    $events->listen(BuildingMenu::class, function (BuildingMenu $event) {
        $event->menu->add(trans('menu.pages'));

        $items = Page::all()->map(function (Page $page) {
            return [
                'text' => $page['title'],
                'url' => route('admin.pages.edit', $page)
            ];
        });

        $event->menu->add(...$items);
    });
}

The above model was returning error, so I had to make some changes:

public function boot(Dispatcher $events)
{
    $events->listen(BuildingMenu::class, function (BuildingMenu $event) {
        $event->menu->add(trans('menu.pages'));

        $items = Page::all()->map(function (Page $page) use ($event){
            $event->menu->add([
                'text' => $page['name'],
                'url' => $page['url']
            ]);;
        });


    });
}

Now it is working, however, I still can not solve the issue of the menu with multiple levels. Another problem factor is that the amount of levels is undefined. How can I create multiple levels considering the above project approach? Whereas in my database I have basically the columns: id, title, url and parent_id.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.