PHPackages                             railken/amethyst-permission - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. railken/amethyst-permission

ActiveLibrary[API Development](/categories/api)

railken/amethyst-permission
===========================

v0.3.1(2y ago)0195MITPHPPHP &gt;=8.2

Since Apr 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/amethyst-php/permission)[ Packagist](https://packagist.org/packages/railken/amethyst-permission)[ RSS](/packages/railken-amethyst-permission/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (9)Versions (31)Used By (0)

amethyst-permission
===================

[](#amethyst-permission)

[![Action Status](https://github.com/amethyst-php/permission/workflows/test/badge.svg)](https://github.com/amethyst-php/permission/actions)

[Amethyst](https://github.com/amethyst-php/amethyst) package.

Define permissions with an extensive customization for your data and routes.

Requirements
============

[](#requirements)

PHP 7.2 and later.

TODO
====

[](#todo)

- Attribute Authorization

Installation
------------

[](#installation)

You can install it via [Composer](https://getcomposer.org/) by typing the following command:

```
composer require amethyst/permission
```

The package will automatically register itself.

Usage
-----

[](#usage)

A simple usage looks like this

```
use Amethyst\Models\Permission;
use Symfony\Component\Yaml\Yaml;

Permission::create([
	'effect' => 'accept',
	'type' => 'data',
	'payload' => Yaml::dump([
		'action' => 'create',
		'data' => 'foo'
	]),
	'agent' => '{{ agent.id }} == 1',
]);
```

Permissions will be automatically reloaded whenever a `eloquent.saved` is fired for `Permission` model.

Effect
------

[](#effect)

The effect can be either `accept` or `deny`. Without any permissions any user is denied to perform anything. If you add both permission accept and deny both of them are applied.

For example you could set "user can see all comments" and "user cannot see this comment". At the end the user can see all comments except the one that you defined.

Type
----

[](#type)

The type of your permission indicate which class will be used to resolve your request.

It can be either `data` or `route`, but you can extend it in `amethyst.permissions.permission`

Agent
-----

[](#agent)

The agent is retrieved through the facade `Illuminate\Support\Facades\Auth` and the method `user()`.

When this field is null it means that it's applied to all agents.

Agent must return a condition true or false.

If you wish to see the syntax see [nicoSWD/php-rule-parser](https://github.com/nicoSWD/php-rule-parser).

Before parsing with the logic parser, a twig parser comes in. The only variable passed is the agent and it is your `App\Models\User`. You can then use whanever logic you want to get the information you want. For example you can filter by any attributes and any relations (e.g. groups): `{{ agent.groups.contains('myGroupName') ? 1 : 0 }} === 1`

Payload
-------

[](#payload)

A payload in YAML the define the specification of your permission. For example for the permission `route` it can be a wildcard for the url.

Payload - Route
---------------

[](#payload---route)

- name: The name of the route you wish to use, you can use wildcard `*`
- url: The url of the route, same like before, you can use the wildcard `*`,
- method: The method of the route

Some examples:

Enable endpoint `/profile` for each user.

```
use Amethyst\Models\Permission;
use Symfony\Component\Yaml\Yaml;

Permission::create([
	'type' => 'route',
	'payload' => Yaml::dump([
		'url' => '/profile'
	])
]);
```

You can also use an array

```
use Amethyst\Models\Permission;
use Symfony\Component\Yaml\Yaml;

Permission::create([
	'type' => 'route',
	'payload' => Yaml::dump([
		'url' => [
			'/profile',
			'/recovery-password'
		],
		'method' => [
			'POST',
			'GET'
		]
	])
]);
```

Enable endpoints foo.\* (foo.index, foo.create, foo.show, foo.update, foo.delete) for user id 2

```
use Amethyst\Models\Permission;
use Symfony\Component\Yaml\Yaml;

Permission::create([
	'type' => 'route',
	'payload' => Yaml::dump([
		'url' => 'foo.*'
	]),
	'agent' => '{{ agent.id }} === 2'
]);
```

Payload - Data
--------------

[](#payload---data)

The following example will permit the user#2 to visualize only the data named `post` that contains in the name `foo`

```
use Amethyst\Models\Permission;
use Symfony\Component\Yaml\Yaml;

Permission::create([
	'type' => 'data',
	'payload' => Yaml::dump([
		'name' => [
			'post'
		],
		'action' => [
			'query',
		],
		'filter' => [
			'name ct "foo"'
		]
	]),
	'agent' => '{{ agent.id }} === 2'
]);
```

List of all actions: `query, create, update, remove`

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~372 days

Total

30

Last Release

766d ago

PHP version history (3 changes)v0.1.0PHP &gt;=7.1

v0.2.0PHP &gt;=7.2

v0.3.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea4a9e56b247008aea4d20bb8a555a9f0cb69d0ac69aa8417b29fc37efa2eb5c?d=identicon)[railken](/maintainers/railken)

---

Top Contributors

[![railken](https://avatars.githubusercontent.com/u/26530231?v=4)](https://github.com/railken "railken (73 commits)")

---

Tags

amethystamethyst-packageapilaravelpermissionutilitylaravelpermissionamethystamethyst-permission

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/railken-amethyst-permission/health.svg)

```
[![Health](https://phpackages.com/badges/railken-amethyst-permission/health.svg)](https://phpackages.com/packages/railken-amethyst-permission)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
