1. Go to this page and download the library: Download napp/aclcore 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/ */
napp / aclcore example snippets
return [
/**
* Define which Eloquent models used by the package
*/
'models' => [
'role' => Napp\Core\Acl\Model\Role::class,
'user' => Illuminate\Foundation\Auth\User::class,
],
/**
* Table names for the package
*/
'table_names' => [
'roles' => 'roles',
'users_roles' => 'users_roles',
],
/**
* The default guard used to authorize users
*/
'guard' => 'web'
];
use Illuminate\Foundation\Auth\User as Authenticatable;
use Napp\Core\Acl\Contract\Role as RoleContract;
use Napp\Core\Acl\Role\HasRole;
class User extends Authenticatable implements RoleContract
{
use HasRole;
}
// authorize a single permission
if (may('users.view')) {
// do something
}
// authorize if **any** of the permissions are valid
if (may(['users.view', 'users.create'])) {
// do something
}
// authorize if **all** of the permissions are valid
if (mayall(['users.view', 'users.create'])) {
// do something
}
// reverse - not logic
if (maynot('users.view')) {
return abort();
}
// check for user role
if (has_role($user, 'manager')) {
// do something
}
// check if user has many roles
if (has_role($user, ['support', 'hr'])) {
// do something
}