https://github.com/railken/permission
A very simple system to handle permissions
https://github.com/railken/permission
library permission php
Last synced: over 1 year ago
JSON representation
A very simple system to handle permissions
- Host: GitHub
- URL: https://github.com/railken/permission
- Owner: railken
- License: mit
- Created: 2017-10-23T22:30:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-24T00:34:53.000Z (over 8 years ago)
- Last Synced: 2025-01-24T08:44:18.550Z (over 1 year ago)
- Topics: library, permission, php
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Permission
A very simple system to handle permissions
## Requirements
PHP 7.0.0 or later.
## Composer
You can install it via [Composer](https://getcomposer.org/) by typing the following command:
```bash
composer require railken/permission
```
## Usage
Add the trait, check [here](https://github.com/railken/permission/blob/master/src/Traits/CanTrait.php) for more info.
```php
use Railken\Permission\Traits\CanTrait;
class User
{
use CanTrait;
}
```
Load all permissions using `setPermissions`
```php
$user->setPermissions([
'me.*',
'all.show',
]);
```
Note: You can use `*` as a wildcard.
Now you're free to test the permission of user
```php
$user->can('me.anything'); // true
$user->can('foo'); // false
$user->can('all.wrong'); // false
$user->can('all.show'); // true
$user->can('all.show.wrong'); // false
```
Check [tests](https://github.com/railken/permission/blob/master/tests/PermissionTest.php) to see more examples;
## License
Open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).