1. Go to this page and download the library: Download orchid/access 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/ */
/**
* User
*/
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Model;
use Orchid\Access\Traits\UserAccess;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, UserAccess;
/**
* @var
*/
protected static $rolesModel = Roles::class;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* @var array
*/
protected $fillable = [
'email',
'permissions',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
}
// It checks the availability of a user in the roles and permissions
Auth:user()->hasAccess('param');
// Get access for the user
Auth:user()->getPermissionsAttribute($permissions);
// Set access for the user
Auth:user()->setPermissionsAttribute($permissions)
// Get roles for the user
Auth:user()->getRoles();
// Check user has role
Auth:user()->inRole($role)
// Add Role for user
Auth:user()->addRole($role)
/**
* Middleware
*/
// To check on each controller add middleware in /Http/Kernel.php
'Access' => \Orchid\Access\Middleware\AccessMiddleware::class,
/**
* Role
*/
// Model Role
use Illuminate\Database\Eloquent\Model;
use Orchid\Access\Traits\RoleAccess;
class Roles extends Model
{
use RoleAccess;
/**
* @var
*/
protected static $usersModel = User::class;
/**
* @var string
*/
protected $table = 'roles';
/**
* @var array
*/
protected $fillable = [
'id',
'name',
'slug',
'permissions',
];
}
$role = Role::getRoleSlug('string');
// Will return all users with that role
$role->getUsers();
// Get access for the role
$role->getPermissionsAttribute($permissions);
// Set access for the role
$role->setPermissionsAttribute($permissions);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.