Core Concepts
Menus
Status: experimental. The menu tables, models and save/delete routes exist, but the menu admin screens do not ship with views yet, and assigning menus to roles (
POST /menus/assign) does nothing. The API may change. Don't build on it for production yet.
Menus are meant to let you build navigation menus whose items link to stored routes and show only to the roles allowed to see them.
Tables#
| Table | Holds |
|---|---|
system_ |
A menu: menu_, menu_, menu_ (main or secondary) |
system_ |
Items in a menu: item_, item_, item_ (parent or child), parent_, route_, item_ |
system_ |
Which role sees which route in a menu: menu_, route_, role_, in_ |
Item links point at system_routes, so run php artisan systemroles:sync first.
What works today#
| Action | Route | Works |
|---|---|---|
| Create or update a menu | POST / |
Yes |
| Add an item (with roles) | POST / |
Yes |
| Delete a menu (and its items and role rows) | DELETE / |
Yes |
| Delete an item | DELETE / |
Yes |
| Move an item up or down | GET . and / |
Yes |
| Renumber items 1..n | GET . |
Yes |
| List / manage screens | GET ., /, /, / |
No view yet |
| Assign a menu to roles | POST . |
Not implemented |
Reading a menu for the current user#
Until the screens ship, you can render a menu yourself:
PHP
use BabeRuka\SystemRoles\Models\SystemMenuItems;
use BabeRuka\SystemRoles\Models\SystemMenusIn;
use BabeRuka\SystemRoles\Models\SystemRoutes;
use BabeRuka\SystemRoles\Services\SystemRolesService;
$roleId = SystemRolesService::roleIdForUser(auth()->id());
$menuId = 1;
$visibleRouteIds = SystemRolesService::isSuperAdminRole($roleId)
? null
: SystemMenusIn::where('menu_id', $menuId)->where('role_id', $roleId)->where('in_role', '1')->pluck('route_id');
$items = SystemMenuItems::where('menu_id', $menuId)
->when($visibleRouteIds, fn ($q) => $q->whereIn('route_id', $visibleRouteIds))
->orderBy('item_sequence')
->get();
$routes = SystemRoutes::whereIn('route_id', $items->pluck('route_id'))->get()->keyBy('route_id');In Blade:
Blade
<ul class="nav">
@foreach ($items as $item)
@php($r = $routes[$item->route_id] ?? null)
@if ($r)
<li><a href="{{ url($r->route_url) }}"><i class="{{ $item->item_icon }}"></i> {{ $item->item_name }}</a></li>
@endif
@endforeach
</ul>Only routes without parameters can be linked this way.