- Roles CRUD: List/Create/Update/Delete actions, controller, requests - Roles Vue pages: Index, Create, Edit (Options API, DashboardLayout) - SidebarNav: filter menu items by user permissions via Inertia shared data - HandleInertiaRequests: share permissions and roles arrays to frontend - HttpKernel: register dashboard.permission middleware alias - SidebarNavItem: add shield-check icon mapping
56 lines
1.9 KiB
PHP
Executable File
56 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Ship\Middleware;
|
|
|
|
use App\Containers\AppStructure\Tasks\GetCachedNavigationDataTask;
|
|
use App\Containers\AppStructure\Tasks\GenerateBreadcrumbsTask;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Middleware;
|
|
use Tightenco\Ziggy\Ziggy;
|
|
|
|
class HandleInertiaRequests extends Middleware
|
|
{
|
|
protected $rootView = 'app';
|
|
|
|
public function __construct(private readonly GenerateBreadcrumbsTask $generateBreadcrumbsTask){}
|
|
|
|
public function version(Request $request): ?string
|
|
{
|
|
return parent::version($request);
|
|
}
|
|
|
|
public function share(Request $request): array
|
|
{
|
|
// Навигация (кешированная)
|
|
$navigation = app(GetCachedNavigationDataTask::class)->run();
|
|
|
|
// Хлебные крошки (автоматически по текущему URL)
|
|
$breadcrumbs = $this->generateBreadcrumbsTask->run();
|
|
|
|
return [
|
|
...parent::share($request),
|
|
'app' => [
|
|
'env' => app()->environment(),
|
|
],
|
|
'auth' => [
|
|
'user' => $request->user() ? $request->user()->only('id', 'name', 'email', 'created_at') : null,
|
|
'permissions' => $request->user()?->getAllPermissions()->pluck('name')->toArray() ?? [],
|
|
'roles' => $request->user()?->getRoleNames()->toArray() ?? [],
|
|
],
|
|
'ziggy' => fn () => [
|
|
...(new Ziggy)->toArray(),
|
|
'location' => $request->url(),
|
|
],
|
|
'navigation' => $navigation,
|
|
'breadcrumbs' => $breadcrumbs, // Добавляем хлебные крошки
|
|
'urlPrev' => function () {
|
|
if (url()->previous() !== url()->current()) {
|
|
return url()->previous();
|
|
}
|
|
return 'empty';
|
|
},
|
|
'yandex_metrika_id' => config('services.yandex_metrika.id'),
|
|
];
|
|
}
|
|
}
|