Reference
Service and Facade API
On this page
BabeRuka\SystemRoles\Services\SystemRolesService#
The main entry point for checks. Static methods can be called directly. Instance methods are available through the container or the facade.
Static methods#
| Method | Returns | Description |
|---|---|---|
superAdminRoleId() |
int |
The configured super admin role id |
isSuperAdminRole($roleId) |
bool |
Whether the id is the super admin role. 0 and negatives are false |
roleIdForUser($userId) |
int |
The user's role id from user_, or 0 |
isSuperAdmin($user = null) |
bool |
Whether the user (default: the logged-in user) has the super admin role. false for guests |
permissionsForRole($roleId) |
array |
`[in_name => 0 |
roleHas($roleId, string $permission) |
bool |
Whether the role has the permission switched on. Matches in_ or in_. Always true for the super admin |
sessionKey(string $key) |
string |
$key with the configured session_ |
Instance methods#
| Method | Returns | Description |
|---|---|---|
getUserRole(int $userId) |
?UserRoles |
The user's user_ row |
updateUserRole(int $userId, array $data) |
?UserRoles |
Fill and save the user's row. null if the user has none. Does not write history or refresh user_ |
createUserRole(array $data) |
UserRoles |
Create a user_ row. Does not write history |
role($roleId) |
?SystemRoles |
Find a role |
$service = app(\BabeRuka\SystemRoles\Services\SystemRolesService::class);
$service->getUserRole(42)?->role?->role_name;To change a role with history and permission refresh, see Assigning Roles → Doing it in code.
SystemRoles facade#
BabeRuka\SystemRoles\Facades\SystemRoles resolves SystemRolesService from the container (binding systemroles). Every method above can be called through it:
use BabeRuka\SystemRoles\Facades\SystemRoles;
SystemRoles::isSuperAdmin();
SystemRoles::roleHas(3, 'invoice.approve');
SystemRoles::getUserRole(42);With auto-discovery the alias SystemRoles is registered globally.
SystemClassesController (controller access checks)#
BabeRuka\SystemRoles\Http\Controllers\SystemRoles\SystemClassesController
| Method | Returns | Description |
|---|---|---|
checkSystemClassesInit($roleId, string $class) |
int |
1 if the role may use the controller, else 0. Super admin always 1. $class may be short or fully qualified |
checkAccess($roleId, string $class) |
true |
Same check; aborts with 403 when denied |
chechAccess(. |
true |
Deprecated alias of checkAccess |
controllerInit() |
true |
Scan controllers into system_ |
addSystemClassIn($classId) |
int |
Create missing "revoke" rows for every role on one controller |
SystemRolesController (session helpers)#
BabeRuka\SystemRoles\Http\Controllers\SystemRoles\SystemRolesController
| Method | Description |
|---|---|
rolesArray($userId) |
Store role_, role_, role_, user_ in the session |
userRole() |
Store and return ['role_ for the logged-in user |
userPermissions($roleId, $force = false) |
Store and return permissionsForRole() in the session. Uses the stored copy unless $force |
checkRole() |
The logged-in user's role id |
init_ |
Fill in missing permission rows for a role. Returns how many were added |
init_ |
Rebuild a user's user_ rows from a role |
nextInSequence() (static) |
Next free in_ |
Scanners#
| Class | Method | Description |
|---|---|---|
Services\ |
scanRoutes() |
Array of every route: uri, methods, name, action, middleware, prefix, controller |
sync() |
Store routes in system_; returns ['created' => n, 'updated' => n] |
|
Services\ |
scanControllers() |
Array of ['filename', 'namespace', 'classname'] for every PHP class in controller_ |
Middleware#
| Alias | Class | Description |
|---|---|---|
super_ |
Http\ |
Allows only the super admin. See Middleware |
| – | Http\ |
Simple auth check (redirects to the login route). Not registered by default |
Models#
All in BabeRuka\SystemRoles\Models. See Database Schema and Models.
SystemRoles, SystemRolesIn, UserRoles, UserRoleHistory, UserRolesIn, SystemClasses, SystemClassesIn, SystemRoutes, SystemRoutesIn, SystemMenus, SystemMenusIn, SystemMenuItems.