{"id":21542377,"url":"https://github.com/amethyst-php/permission","last_synced_at":"2026-05-22T14:12:00.467Z","repository":{"id":56946948,"uuid":"181377050","full_name":"amethyst-php/permission","owner":"amethyst-php","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-05T11:00:34.000Z","size":108,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T13:50:22.019Z","etag":null,"topics":["amethyst","amethyst-package","api","laravel","permission","utility"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amethyst-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-14T22:36:25.000Z","updated_at":"2024-03-29T20:30:21.000Z","dependencies_parsed_at":"2025-01-24T08:41:08.449Z","dependency_job_id":"9f792066-b7fa-4d5d-b4f1-b1d21b265374","html_url":"https://github.com/amethyst-php/permission","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amethyst-php%2Fpermission","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amethyst-php%2Fpermission/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amethyst-php%2Fpermission/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amethyst-php%2Fpermission/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amethyst-php","download_url":"https://codeload.github.com/amethyst-php/permission/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244130277,"owners_count":20402753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amethyst","amethyst-package","api","laravel","permission","utility"],"created_at":"2024-11-24T05:09:24.289Z","updated_at":"2026-05-22T14:11:55.434Z","avatar_url":"https://github.com/amethyst-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# amethyst-permission\n\n[![Action Status](https://github.com/amethyst-php/permission/workflows/test/badge.svg)](https://github.com/amethyst-php/permission/actions)\n\n[Amethyst](https://github.com/amethyst-php/amethyst) package.\n\nDefine permissions with an extensive customization for your data and routes.\n\n# Requirements\n\nPHP 7.2 and later.\n\n# TODO\n\n- [ ] Attribute Authorization\n\n## Installation\n\nYou can install it via [Composer](https://getcomposer.org/) by typing the following command:\n\n```bash\ncomposer require amethyst/permission\n```\n\nThe package will automatically register itself.\n\n## Usage\n\nA simple usage looks like this\n\n```php\nuse Amethyst\\Models\\Permission;\nuse Symfony\\Component\\Yaml\\Yaml;\n\nPermission::create([\n\t'effect' =\u003e 'accept',\n\t'type' =\u003e 'data',\n\t'payload' =\u003e Yaml::dump([\n\t\t'action' =\u003e 'create',\n\t\t'data' =\u003e 'foo'\n\t]),\n\t'agent' =\u003e '{{ agent.id }} == 1',\n]);\n```\n\nPermissions will be automatically reloaded whenever a `eloquent.saved` is fired for `Permission` model.\n\n## Effect\n\nThe 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.\n\nFor 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.\n\n## Type\n\nThe type of your permission indicate which class will be used to resolve your request.\n\nIt can be either `data` or `route`, but you can extend it in `amethyst.permissions.permission`\n\n## Agent\n\nThe agent is retrieved through the facade `Illuminate\\Support\\Facades\\Auth` and the method `user()`.\n\nWhen this field is null it means that it's applied to all agents.\n\nAgent must return a condition true or false.\n\nIf you wish to see the syntax see [nicoSWD/php-rule-parser](https://github.com/nicoSWD/php-rule-parser).\n\nBefore 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`\n\n## Payload\n\nA payload in YAML the define the specification of your permission. For example for the permission `route` it can be a wildcard for the url.\n\n## Payload - Route\n\n- name: The name of the route you wish to use, you can use wildcard `*`\n- url: The url of the route, same like before, you can use the wildcard `*`,\n- method: The method of the route\n\nSome examples:\n\nEnable endpoint `/profile` for each user.\n\n```php\nuse Amethyst\\Models\\Permission;\nuse Symfony\\Component\\Yaml\\Yaml;\n\nPermission::create([\n\t'type' =\u003e 'route',\n\t'payload' =\u003e Yaml::dump([\n\t\t'url' =\u003e '/profile'\n\t])\n]);\n```\n\nYou can also use an array\n\n```php\nuse Amethyst\\Models\\Permission;\nuse Symfony\\Component\\Yaml\\Yaml;\n\nPermission::create([\n\t'type' =\u003e 'route',\n\t'payload' =\u003e Yaml::dump([\n\t\t'url' =\u003e [\n\t\t\t'/profile',\n\t\t\t'/recovery-password'\n\t\t],\n\t\t'method' =\u003e [\n\t\t\t'POST',\n\t\t\t'GET'\n\t\t]\n\t])\n]);\n```\n\nEnable endpoints foo.* (foo.index, foo.create, foo.show, foo.update, foo.delete) for user id 2\n\n```php\nuse Amethyst\\Models\\Permission;\nuse Symfony\\Component\\Yaml\\Yaml;\n\nPermission::create([\n\t'type' =\u003e 'route',\n\t'payload' =\u003e Yaml::dump([\n\t\t'url' =\u003e 'foo.*'\n\t]),\n\t'agent' =\u003e '{{ agent.id }} === 2'\n]);\n```\n\n## Payload - Data\n\nThe following example will permit the user#2 to visualize only the data named `post` that contains in the name `foo`\n\n```php\nuse Amethyst\\Models\\Permission;\nuse Symfony\\Component\\Yaml\\Yaml;\n\nPermission::create([\n\t'type' =\u003e 'data',\n\t'payload' =\u003e Yaml::dump([\n\t\t'name' =\u003e [\n\t\t\t'post'\n\t\t],\n\t\t'action' =\u003e [\n\t\t\t'query',\n\t\t],\n\t\t'filter' =\u003e [\n\t\t\t'name ct \"foo\"'\n\t\t]\n\t]),\n\t'agent' =\u003e '{{ agent.id }} === 2'\n]);\n```\nList of all actions: `query, create, update, remove`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famethyst-php%2Fpermission","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famethyst-php%2Fpermission","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famethyst-php%2Fpermission/lists"}