PHP code example of mogody / hyperf-permission
1. Go to this page and download the library: Download mogody/hyperf-permission 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/ */
mogody / hyperf-permission example snippets
$roles = Role::with(['users', 'perms'])->get();
foreach ($roles as $role) {
if ($role->perms) {
foreach ($role->perms as $perm) {
Enforcer::addPermissionForUser($role->name, $perm->name, 'ANY');
}
}
if ($role->users) {
foreach ($role->users as $user) {
Enforcer::addRoleForUser($user->username, $role->name);
}
}
}