S
S
sr362019-12-13 13:30:47
Laravel
sr36, 2019-12-13 13:30:47

How to implement record counter in Laravel, AdminLTE?

Good day to all.
The project uses AdminLTE as an admin panel (package - jeroennoten/laravel-adminlte).
It is necessary in the menu, opposite the item, to write also the number of records in the
Ads database (5)
But the menu is written there in the config file

[
            'text'        => 'Объявления',
            'url'         => 'admin/offers',
            'icon'        => 'far fa-fw fa-file',
            'label'       => 5,
            'label_color' => 'success',
        ]

The value of the label key is the number that is shown opposite.
How can I dynamically update this number?
I tried this . It gives an error 500, and on all pages, the error text does not show on the screen. APP_DEBUG is set to true.
DB::table('offers')->where('new',true)->count();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sr36, 2019-12-13
@sr36

Everything, I figured it out myself.
For those who ever have this problem.
It is necessary to remove such menu items from the config and add them to the
AppServiceProvider

public function boot(Dispatcher $events)
    {
        $events->listen(BuildingMenu::class, function (BuildingMenu $event) {
            $event->menu->add('MAIN NAVIGATION');
            $event->menu->add([
                'text'        => 'Объявления',
                'url'         => 'admin/offers',
                'icon'        => 'far fa-fw fa-file',
                'label'       => DB::table('offers')->where('new',true)->count(),
                'label_color' => 'success',
            ]);
        });
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question