Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adminlte in Laravel sidebar update label on runtime

This is my menu array format in adminlte.php

'menu' => [
        [
            'text' => 'Dashboard',
            'url'  => '/dashboard',
            'icon' => 'dashboard',
            'label'=> $test // how to pass variable here or alternative way without using building menu
            'label-color' => 'success'
        ],
],

How can I pass count variable to the label on runtime?

I knew there is a way to do it with building menu but, need to rebuild the whole thing inside adminlte.php . I need to pass count variable to it, if I put in adminlte.php, the variable will be undefined.

Can the building menu used to update the menu label or append the label and label-color into it?

Is there a method to override the current value in label by passing variable to it?

like image 342
Crazy Avatar asked Dec 19 '25 22:12

Crazy


1 Answers

From Laravel-AdminLTE documentation:

It is also possible to configure the menu at runtime, e.g. in the boot of any service provider. Use this if your menu is not static, for example when it depends on your database or the locale. It is also possible to combine both approaches. The menus will simply be concatenated and the order of service providers determines the order in the menu.

To configure the menu at runtime, register a handler or callback for the MenuBuilding event, for example in the boot() method of a service provider:

use Illuminate\Contracts\Events\Dispatcher;
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu;

class AppServiceProvider extends ServiceProvider
{

    public function boot(Dispatcher $events)
    {
        $events->listen(BuildingMenu::class, function (BuildingMenu $event) {
            $event->menu->add('MAIN NAVIGATION');
            $event->menu->add([
                'text' => 'Blog',
                'url' => 'admin/blog',
            ]);
        });
    }

}

https://github.com/jeroennoten/Laravel-AdminLTE#menu-configuration-at-runtime

like image 180
Vladimir Sukhov Avatar answered Dec 21 '25 10:12

Vladimir Sukhov