SaborGestion ships with one custom middleware class:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Henry4ndrew/saborGestion/llms.txt
Use this file to discover all available pages before exploring further.
RoleMiddleware. It sits on top of Laravel’s built-in auth middleware and enforces role-based access control for every protected route.
RoleMiddleware
File: app/Http/Middleware/RoleMiddleware.php
How it works
Authentication check
The middleware first calls
Auth::check(). If the user is not authenticated, they are immediately redirected to /login.Role retrieval
The authenticated user’s
role column is read from Auth::user()->role. The four possible values are admin, mesero, cocinero, and cajero.Role authorization
The middleware receives one or more allowed roles as variadic parameters (e.g.,
'admin', 'cocinero'). It checks whether the user’s role is in that list using in_array().Allowed roles
Therole column on the users table is an enum with four values:
| Value | Description |
|---|---|
admin | Full access to all sections |
mesero | Tables, waiter dashboard |
cocinero | Products, inventory, cook dashboard |
cajero | Orders, comandas, delivery, billing, cashier dashboard |
Registering the middleware
RoleMiddleware is registered as an aliased middleware so it can be referenced as 'role' in route definitions. Registration is in app/Http/Kernel.php under $routeMiddleware:
SaborGestion uses the
app/Http/Kernel.php approach for middleware registration. The $routeMiddleware array maps the string alias 'role' to the RoleMiddleware class, which is then referenced in route definitions as ->middleware('role:admin,cocinero').Usage in routes/web.php
All application routes sit inside an outer auth middleware group. RoleMiddleware is applied as a second layer using ->middleware('role:role1,role2').
Applying to resource routes
Route-to-role mapping
| Route prefix | Allowed roles |
|---|---|
/productos | admin, cocinero |
/inventario | admin, cocinero |
/mesas | admin, mesero |
/pedidos | admin, cajero |
/comandas | admin, cajero |
/delivery | admin, cajero |
/facturas | admin, cajero |
/pagos | admin, cajero |
/cierres | admin, cajero |
/usuarios | admin only |
/dashboard/administrador | auth only (role check in controller) |
/dashboard/mesero | auth only |
/dashboard/cocinero | auth only |
/dashboard/cajero | auth only |
Error response
When the role check fails, Laravel renders its default 403 error page. You can customize the message by creatingresources/views/errors/403.blade.php:
User model helpers
TheUser model exposes four boolean helper methods that mirror the role values: