PHP code example of ezijing-mse-hyperf / permission
1. Go to this page and download the library: Download ezijing-mse-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/ */
ezijing-mse-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);
}
}
}