PHP code example of gusmanwidodo / auth-kit-permissions
1. Go to this page and download the library: Download gusmanwidodo/auth-kit-permissions 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/ */
gusmanwidodo / auth-kit-permissions example snippets
use Gusmanwidodo\AuthKitPermissions\PermissionManager;
use Gusmanwidodo\AuthKitPermissions\Support\Scope;
$pm = app(PermissionManager::class);
// Static, in-memory, ZERO queries:
$pm->check('App\\User', $user->id, 'post.update', staticRoles: ['author']); // true
// Dynamic (DB) role, resolved once then memoized:
$pm->check('App\\User', $user->id, 'post.delete'); // 1 query, then 0
use Gusmanwidodo\AuthKitPermissions\HasRoles;
class User extends Authenticatable
{
use HasRoles; // reads static roles from a `roles` attribute by default
}
$user->can('post.update'); // hybrid static + dynamic check
use Gusmanwidodo\AuthKitPermissions\RoleService;
$svc = app(RoleService::class);
$role = $svc->createRole('editor', ['post.delete']); // global scope
$svc->assign('App\\User', $user->id, $role);
// In any plugin implementing HasHooks:
public function beforeHooks(): array
{
return [
'permission.check' => function ($ctx) {
if (isSuspended($ctx->get('subject_id'))) {
$ctx->set('allow', false)->stop(); // hard deny
}
},
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.