mibo/px

PHP Library for Permissions [RBAC]

1.1.6 2024-03-17 12:52 UTC

This package is auto-updated.

Last update: 2024-04-17 13:04:27 UTC


README

codecov

Permissions and their evaluating. Role Based System.

Implementation

composer require mibo/px

Requirements

  • PHP ^8.0
  • illuminate/support ^9.36

Usage

// Load the user that has permissions.
/** @var \MiBo\PX\Contracts\HasPermissionsInterface $user */
$user;

if ($user->hasPermission("my.own.permission")) {
    // Do some action
} else {
    // You may log that the user is missing required permission.
}

When implementing the interface, consider to use provided trait. If doing so, call registerPermissions method with all available permissions for the user:

class MyUser implements \MiBo\PX\Contracts\HasPermissionsInterface
{
    use \MiBo\PX\Contracts\HasPermissionsTrait;
    
    public function __construct()
    {
        $this->registerPermissions(
            [
                "my.own.permission",
                "my.another.permission"
            ]
        );
    }
}