Laravel-adminlte: QUESTION: Dynamic menu items from controllers

Created on 21 Apr 2020  路  6Comments  路  Source: jeroennoten/Laravel-AdminLTE

What's the best way to add to the menu item on the fly from a controller? For example, I have 10 courses I want to append under 'Course Manager' and when 'Course 1' is clicked I want to display Chapters under Course 1.

Thanks

Most helpful comment

I've tested it some time ago it worked with simple controllers, you only need to load the Dispatcher for it.

All 6 comments

@dunfy Only getting started with this myself but not sue if this might help https://github.com/jeroennoten/Laravel-AdminLTE#6113-menu-configuration-at-runtime

@Nardusgc I tried that by listening to the event in the controller, but I suspect it's already fired by the time the controller action is executed.

Event::listen(BuildingMenu::class, function (BuildingMenu $event) { $event->menu->add([ 'text' => 'Blog', 'url' => 'admin/blog', ]); });

Guessing it's not possible, I'll have to dig in to the code later if nobody knows.

I guess the only way is to use the example above and inspect the route and parameters and assign menu items based on the route that's fired? Only problem is it's going to duplicate code and calls to the database.

I've tested it some time ago it worked with simple controllers, you only need to load the Dispatcher for it.

@REJack we should work on our wiki with more examples... :)

@REJack @lacodimizer sorry guys, documentation is fine, I forgot to include use JeroenNoten\LaravelAdminLte\Events\BuildingMenu;

Added that in and the event worked from within the controller, my bad.

Cheers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Basili0 picture Basili0  路  5Comments

iHeartBard picture iHeartBard  路  4Comments

samuelm77 picture samuelm77  路  4Comments

bbdangar picture bbdangar  路  5Comments

WillieOng-HK picture WillieOng-HK  路  4Comments