1. Go to this page and download the library: Download artisanpack-ui/rbac 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/ */
artisanpack-ui / rbac example snippets
use ArtisanPackUI\Rbac\Concerns\HasPermissions;
use ArtisanPackUI\Rbac\Concerns\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasPermissions;
use HasRoles;
}
$user->roles; // collection of Role
$user->hasRole('admin'); // by name, Role instance, or Collection
$user->assignRole('admin'); // idempotent; no-op for unknown role names
$user->removeRole('admin');
$user->hasPermissionTo('posts.publish');
$user->hasPermission('posts.publish'); // alias of hasPermissionTo
$user->flushPermissionCache(); // call after manual relationship mutations
namespace App\Models;
use ArtisanPackUI\Rbac\Models\Role as BaseRole;
class Role extends BaseRole
{
protected $table = 'roles';
public function policies(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Policy::class);
}
}