An open API service indexing awesome lists of open source software.

https://github.com/perer876/guard

Lightweight, enum-based definition, querying and mapping of permissions in PHP applications.
https://github.com/perer876/guard

authorization permission rbac

Last synced: 5 months ago
JSON representation

Lightweight, enum-based definition, querying and mapping of permissions in PHP applications.

Awesome Lists containing this project

README

          

> [!IMPORTANT]
> Still in development, not feature complete.

# Guard

Lightweight, enum-based definition, querying and mapping of permissions in PHP applications.

## Usage

You can define roles and permissions using an enum.

For example, you can define roles like this:
```php
*/
#[Override]
public function getRoles(): iterable
{
yield $this->role;
}

/** @return array */
protected function casts(): array
{
return [
'role' => UserRole::class,
];
}

/* ... */
}
```

In a policy, for example, you can check the user model permissions like this:

```php
$user->hasPermission(TodoPermission::ViewAny);
```

## Installation

You can install the package via Composer:
```bash
composer require perer876/permission:v1.0.0-alpha.2
```

## Documentation

Coming soon.