{"id":15067051,"url":"https://github.com/akiyamasm/maravel-permissions","last_synced_at":"2025-07-18T01:12:15.177Z","repository":{"id":56990809,"uuid":"267576134","full_name":"akiyamaSM/maravel-permissions","owner":"akiyamaSM","description":"Because in the Maravelous univer every user deserves super power","archived":false,"fork":false,"pushed_at":"2021-02-20T15:40:24.000Z","size":27,"stargazers_count":142,"open_issues_count":0,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-20T02:06:18.482Z","etag":null,"topics":["abilities","laravel","permissions","php","roles"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akiyamaSM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-05-28T11:50:45.000Z","updated_at":"2024-10-24T06:04:26.000Z","dependencies_parsed_at":"2022-08-21T12:20:29.471Z","dependency_job_id":null,"html_url":"https://github.com/akiyamaSM/maravel-permissions","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fmaravel-permissions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fmaravel-permissions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fmaravel-permissions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fmaravel-permissions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akiyamaSM","download_url":"https://codeload.github.com/akiyamaSM/maravel-permissions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230523761,"owners_count":18239445,"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":["abilities","laravel","permissions","php","roles"],"created_at":"2024-09-25T01:15:45.836Z","updated_at":"2024-12-20T02:06:32.757Z","avatar_url":"https://github.com/akiyamaSM.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grant Users the superpower of Marvel characters\n![inani-user2](https://user-images.githubusercontent.com/12276076/83249747-f7a65800-a19e-11ea-950f-fdaba4981829.png)\n\n\n## Download\n\n```bash\ncomposer require inani/maravel-permissions\n```\n\n## Installation\n\nThen include the service provider inside `config/app.php`. (You can skipp it if it's in Laravel 5.5 or higher)\n\n```php\n'providers' =\u003e [\n    ...\n    Inani\\Maravel\\Providers\\MaravelServiceProvider::class,\n    ...\n];\n```\nPublish resources, and migrate\n\n```bash\nphp artisan vendor:publish\n```\n\n\nPS : You can edit `2020_05_27_221346_add_role_id_to_users` migration to link it with the correct user table\n\nEdit the `config/maravels.php` with the correct values\n\n```php\n\u003c?php\n\nreturn [\n    // Define the list of actions to be checked against\n    'actions' =\u003e [\n        'add', 'delete', 'create', 'search', 'update'\n    ],\n\n    // define the class path for the entities\n    'entities' =\u003e [\n        \\App\\Models\\User::class,\n    ],\n];\n\n```\nAnd then migrate\n\n```bash\nphp artisan migrate\n```\n## Setup a Model\n\nTo setup the user model, all you have to do is add (and import) the `IsMarvel` trait.\n\n```php\nuse Inani\\Maravel\\HasRole;\n\nclass User extends Model\n{\n    use HasRole;\n    ...\n}\n```\n\n## Usage\n\n## All roles are role and permissions are powers\nBecause every user deserves to be a hero, The Maravel API is based on the Marvel Jargon, and here are how it can be used \n\n```php\n// Having a user\n$user = User::first();\n\n// Create a new role, description is not mandotary\n$userManager = RoleBuilder::create('User Manager', 'The role to manage users')\n                -\u003ehavingPower([\n                   'name' =\u003e 'can_update',\n                   'description' =\u003e 'The abilitiy to update a user',\n                   'action' =\u003e 'update',\n                   'entity' =\u003e \\App\\Models\\User::class,\n               ]);\n\n// we can grant a power to it\n$userManager = RoleBuilder::of($userManager)\n                        -\u003egrant([\n                             'name' =\u003e 'can_create',\n                             'description' =\u003e 'The abilitiy to create a user',\n                             'action' =\u003e 'create',\n                             'entity' =\u003e \\App\\Models\\User::class,\n                         ]);\n\n// Or take it off\n$ability = Ability::first();\n\n$storm = RoleBuilder::of($userManager)-\u003etakeOff($ability);\n\n\n// bless the user with the abilities of the role\n$user-\u003eroleManager()-\u003eblessWith($storm);\n\n\n// check if it has the ability\n$user-\u003eroleManager()-\u003eowns($ability);\n\n// check if it has one of the provided abilities\n$user-\u003eroleManager()-\u003eownsOneOf([$ability, $anOtherAbility]);\n\n// make it human again (remove its role)\n$user-\u003eroleManager()-\u003ehumanize();\n\n```\n\nYou can also manage the instances directly\n```php\n\n// Create Ability\n$ability = Ability::create([\n    'name' =\u003e 'post_write',\n    'description' =\u003e 'Abitlity to create new Posts',\n    'action' =\u003e 'add',\n    'entity' =\u003e \\App\\Models\\Post::class,\n]);\n\n// Create a Marvel\n$writer = Role::create([\n    'name' =\u003e 'Webmaster',\n    'description' =\u003e 'A Role that allows you create new posts'\n]);\n\n// Grant the ability\n$writer-\u003egrant($ability);\n\n// remove a certain ability\n$writer-\u003etakeOff($ability);\n\n// remove all and keep only those\n$abilities = [1, 2]; // or the models\n$writer-\u003ekeep($abilities);\n\n// bless it to our user\n$user = \\App\\Models\\User::first();\n\n$user-\u003eroleManager()-\u003eblessWith($writer);\n```\n\n## Am I missing something?\nSubmit a PR or issue with details!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakiyamasm%2Fmaravel-permissions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakiyamasm%2Fmaravel-permissions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakiyamasm%2Fmaravel-permissions/lists"}