jeroennoten / Laravel-AdminLTE

Easy AdminLTE integration with Laravel
MIT License
3.78k stars 1.08k forks source link

[FEATURE] Sidebar Menu Logo Dynamic #1250

Closed guga121 closed 5 months ago

guga121 commented 5 months ago

Hello, I don´t now if it can be done or not. I want to load dinamically the sidebar brand logo image so the company logged in can had it's logo and name on the menu.

I need to pass this variables to the adminlte.php on the config folder: image path, image name, brand name.

Thanks in advance if anyone can help me with this.

guga121 commented 5 months ago

I forgot. Also, preloader image!

dfsmania commented 5 months ago

In Laravel, you may change configuration values at runtime, please check the next issues, they matches with your problem:

guga121 commented 5 months ago

Thank you very much for your help!! I can solve it with it.

REFERENCE PAGES (mix of both): https://github.com/jeroennoten/Laravel-AdminLTE/issues/510 https://github.com/jeroennoten/Laravel-AdminLTE/wiki/Menu-Configuration

Solution: edit file EventServiceProvider on folder: Providers/EventServiceProvider.php

add this use:
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu;

Then on boot function add this for menu add item:

Event::listen(BuildingMenu::class, function (BuildingMenu $event) {
    // Add some items to the menu...
    $event->menu->add('MAIN NAVIGATION');
    $event->menu->add([
        'text' => 'Blog',
        'url' => 'admin/blog',
    ]);
});

or this for dynamic logo:

Event::listen(BuildingMenu::class, function (BuildingMenu $event) {
    $user = Auth::user();

    // Use the model you want where your logo images are, in this case is user, but it can be any other database table.

    config(['adminlte.logo_img' => 'image path to file']);
    config(['adminlte.logo_img_xl' => 'image path to file xl']);
});

@dfsmania