LAR_Maintenance/app/Http/Middleware/GenerateMenus.php
JonatanRek 571df9a0a4 Fixes
2024-07-30 18:13:21 +02:00

73 lines
2.5 KiB
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use SteelAnts\LaravelBoilerplate\Facades\Menu;
use Symfony\Component\HttpFoundation\Response;
class GenerateMenus
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if ($request->route()->getName() === 'livewire.message') {
return $next($request);
}
if (!auth()->check()) {
return $next($request);
}
Menu::make('main-menu', function ($menu) {
$systemRoutes = [
'boilerplate::ui.home' => [' fas fa-home', 'home'],
'boilerplate::ui.host' => [' fas fa-server', 'host'],
'boilerplate::ui.maintenance' => [' fas fa-calendar', 'maintenance'],
];
foreach ($systemRoutes as $title => $route_data) {
$icon = $route_data[0];
$route = $route_data[1];
$menu = $menu->add($title, [
'id' => strtolower($title),
'icon' => $icon,
'route' => $route,
]);
}
});
//CHECK IF USER IS SYSTEM ADMIN
Menu::make('system-menu', function ($menu) {
$systemRoutes = [
'boilerplate::ui.audit' => ['fas fa-eye', 'system.audit.index'],
'boilerplate::ui.api' => ['fas fa-file-archive', 'system.api.index'],
'boilerplate::ui.user' => ['fas fa-users', 'system.user.index'],
'boilerplate::subscriptions.title' => ['fas fa-dollar-sign', 'system.subscription.index'],
'boilerplate::ui.log' => ['fas fa-bug', 'system.log.index'],
'boilerplate::ui.jobs' => ['fas fa-business-time', 'system.jobs.index'],
'boilerplate::ui.cache' => ['fas fa-box', 'system.cache.index'],
'boilerplate::ui.backup' => ['fas fa-file-archive', 'system.backup.index']
];
foreach ($systemRoutes as $title => $route_data) {
$icon = $route_data[0];
$route = $route_data[1];
$menu = $menu->add($title, [
'id' => strtolower($title),
'icon' => $icon,
'route' => $route,
]);
}
});
return $next($request);
}
}