LAR_Maintenance/app/Http/Middleware/GenerateMenus.php
2024-08-06 16:57:48 +02:00

91 lines
3.0 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.planned' => [' fas fa-home', 'maintenance.planned'],
];
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,
]);
}
});
Menu::make('settings-menu', function ($menu) {
$systemRoutes = [
'Host' => [' fas fa-server', 'host'],
'Maintenance' => [' fas fa-calendar', 'maintenance'],
'Tasks' => [' fas fa-list', 'tasks'],
];
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);
}
}