I was wondering, is there a more elegant way that we can set different menus based on route.
For example the admin group in the routes.php to have menu A and the user group to have menu B
Right now, what I've done is setting an empty menu in the config/adminlte.php and then in the routes.php, i'm creating the menu per group,
Route::group(['prefix' => 'admin'], function () {
Route::get('dashboard', function () {
Event::listen('JeroenNoten\LaravelAdminLte\Events\BuildingMenu', function ($event) {
$event->menu->add('MAIN NAVIGATION');
$event->menu->add([
'text' => 'Blog',
'url' => 'admin/blog',
]);
});
return view('welcome');
});
});
Sorry for all these questions, but I think that you have been through these issues before me, and it would be a pitty to recreate the wheel
You could solve this for example with a route group middleware. Run artisan make:middleware AdminMenu and artisan make:middleware UserMenu. You can find the created middleware in the app/Http/Middleware directory. Add the menu configuration code above return $next($request); in the middleware. In app/Http/Kernel.php, add 'menu.admin' => AdminMenu::class and 'menu.user' => UserMenu::class to the $routeMiddleware array (don't forget to import the classes at the top). Then in your routes.php:
Route::group(['prefix' => 'admin', 'middleware' => 'menu.admin'], function () {
Route::get('dashboard', function () {
return view('welcome');
});
});
Route::group(['prefix' => 'user', 'middleware' => 'menu.user'], function () {
Route::get('dashboard', function () {
return view('welcome');
});
});
Alternatively, you could use just one middleware with parameters if that is more convenient (for example if you have menu items that both groups need).
may I see your config/adminlte.php for the menu ??
how can I use route instead of url in menu configuration
example settings.index
Based on the answers provided above this is how i implemented mine,
2.created to files in the config directory to hold individual group route arrays
and the other one
Administration
Self Service
You can aslo add permissions to the menu items,Hope this helps somebody, Any suggestions are welcomed
Based on the answers provided above this is how i implemented mine,
- Cleared the adminlte.php menu because both groups will see different menus
2.created to files in the config directory to hold individual group route arrays
- The administration routes in the administration.php
and the other one
- I then created a middleware that accepts a menu type paramenter and used that to determine the route arrays to render
- Added the middleware to my route group routes
- this renders different menu for the different route groups
Administration
Self Service
You can aslo add permissions to the menu items,Hope this helps somebody, Any suggestions are welcomed
Thank you very much. You saved my day.
Thank you very much. You saved my day.
you are most welcome, glad it helped
Excellent solution my friend! but... I keep getting : Class 'App\Http\MiddlewareEvent' not found
Any clue?
Excellent solution my friend! but... I keep getting : Class 'App\Http\MiddlewareEvent' not found
Any clue?
sorry to here that, These are the classes i included at the top of the file, I am guessing you need the last one
(use Illuminate\Support\FacadesEvent;). Try importing it.
use JeroenNoten\LaravelAdminLteEvents\BuildingMenu;
use Closure;
use Illuminate\Support\FacadesEvent;
Most helpful comment
Based on the answers provided above this is how i implemented mine,
2.created to files in the config directory to hold individual group route arrays
and the other one

Administration

Self Service
You can aslo add permissions to the menu items,Hope this helps somebody, Any suggestions are welcomed