PHP code example of archeenic / laram-permission-registry
1. Go to this page and download the library: Download archeenic/laram-permission-registry library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
archeenic / laram-permission-registry example snippets
use ArcheeNic\PermissionRegistry\Facades\PermissionRegistry;
// Проверка прав доступа
if (PermissionRegistry::hasPermission($userId, 'service_name', 'permission_name')) {
// Пользователь имеет доступ
}
// Валидация значения поля доступа
if (PermissionRegistry::validateField($userId, 'service_name', 'permission_name', 'field_name', 'value')) {
// Значение поля валидно
}
// Получение всех доступов пользователя
$permissions = PermissionRegistry::getUserPermissions($userId);
// Выдача доступа
PermissionRegistry::grantPermission(
$userId,
'service_name',
'permission_name',
['field_id' => 'value'], // значения полей
['reason' => 'Requested by admin'], // метаданные
'2023-12-31 23:59:59' // срок действия
);
// Отзыв доступа
PermissionRegistry::revokePermission($userId, 'service_name', 'permission_name');
// Синхронизация доступов на основе должностей и групп пользователя
PermissionRegistry::syncUserPermissions($userId);
Route::middleware(['permission:service_name,permission_name'])->group(function () {
// Маршруты, защищенные проверкой прав
});