{"id":21069052,"url":"https://github.com/kettasoft/gatekeeper","last_synced_at":"2026-04-09T03:33:44.898Z","repository":{"id":182043343,"uuid":"667818796","full_name":"kettasoft/gatekeeper","owner":"kettasoft","description":"A lightweight and powerful package for handling permissions and provisions in Laravel","archived":false,"fork":false,"pushed_at":"2023-09-12T17:02:26.000Z","size":102,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-04T12:52:33.095Z","etag":null,"topics":["application-security","authorization","checker","checks","gate","gatekeeper","keeper","laravel","permissions","php","rbac","roles","security"],"latest_commit_sha":null,"homepage":"","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/kettasoft.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":"2023-07-18T11:21:35.000Z","updated_at":"2025-07-15T11:33:23.000Z","dependencies_parsed_at":"2024-11-19T18:54:34.740Z","dependency_job_id":null,"html_url":"https://github.com/kettasoft/gatekeeper","commit_stats":null,"previous_names":["kettasoft/gatekeeper"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/kettasoft/gatekeeper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Fgatekeeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Fgatekeeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Fgatekeeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Fgatekeeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kettasoft","download_url":"https://codeload.github.com/kettasoft/gatekeeper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Fgatekeeper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31584638,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["application-security","authorization","checker","checks","gate","gatekeeper","keeper","laravel","permissions","php","rbac","roles","security"],"created_at":"2024-11-19T18:31:08.205Z","updated_at":"2026-04-09T03:33:44.860Z","avatar_url":"https://github.com/kettasoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gatekeeper\nThis package provides a comprehensive system for managing roles and permissions in Laravel applications. It allows for easy creation and management of roles, assigning permissions to specific roles, and controlling access to different parts of the application based on a user's assigned roles and permissions.\n\n[![Total Downloads](https://img.shields.io/packagist/dt/kettasoft/gatekeeper?style=for-the-badge)](https://packagist.org/packages/kettasoft/gatekeeper)\n[![Latest Stable Version](http://poser.pugx.org/kettasoft/gatekeeper/v?style=for-the-badge)](https://packagist.org/packages/kettasoft/gatekeeper)\n[![License](http://poser.pugx.org/kettasoft/gatekeeper/license?style=for-the-badge)](https://packagist.org/packages/kettasoft/gatekeeper)\n[![PHP Version Require](http://poser.pugx.org/kettasoft/gatekeeper/require/php?style=for-the-badge)](https://packagist.org/packages/kettasoft/gatekeeper)\n\n## Installation\n\n### You can install the package using composer:\n\n```bash\ncomposer require kettasoft/gatekeeper\n```\n\nIn Laravel 5.5 the service provider will automatically get registered. In older versions of the framework, you must install the service provider:\n\n```php\n// config/app.php\n'providers' =\u003e [\n    ...\n    Kettasoft\\Gatekeeper\\Providers\\GatekeeperServiceProvider::class,\n];\n```\n\n### publish the config/gatekeeper.php config\n```bash\nphp artisan vendor:publish --provider=\"Kettasoft\\Gatekeeper\\Providers\\GatekeeperServiceProvider\" --tag=\"config\"\n```\n### WARNING\nIf this command did not publish any files, chances are, the Laratrust service provider hasn't been registered. Try clearing your configuration cache\n```bash\nphp artisan config:clear\n```\n\n### Run the setup command:\n\nIMPORTANT: Before running the command go to your config/gatekeeper.php file and change the values according to your needs.\n```bash\nphp artisan gatekeeper:migrate\n```\n### This command will generate the migrations, create the Role and Permission models\n\n```php\nuse Kettasoft\\Gatekeeper\\Contracts\\GatekeeperInterface;\nuse Kettasoft\\Gatekeeper\\Traits\\Gatekeeper;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable implements GatekeeperInterface\n{\n    use Gatekeeper;\n\n    // ...\n}\n```\n\n### Dump the autoloader:\n```bash\ncomposer dump-autoload\n```\n\n### Run the migrations:\n```bash\nphp artisan migrate\n```\n\n## Roles \u0026 Permissions\n\n### Setting things up\nLet's start by creating the following Roles:\n```php\n$owner = Role::create([\n    'name' =\u003e 'owner',\n    'display_name' =\u003e 'Project Owner', // optional\n    'description' =\u003e 'User is the owner of a given project', // optional\n]);\n\n$admin = Role::create([\n    'name' =\u003e 'admin',\n    'display_name' =\u003e 'User Administrator', // optional\n    'description' =\u003e 'User is allowed to manage and edit other users', // optional\n]);\n```\nRole Assignment \u0026 Removal:\n```php\n$user-\u003eaddRole($admin); // parameter can be a Role object, array, id or the role string name\n// equivalent to $user-\u003eroles()-\u003eattach([$admin-\u003eid]);\n\n$user-\u003eaddRoles([$admin, $owner]); // parameter can be a Role object, array, id or the role string name\n// equivalent to $user-\u003eroles()-\u003eattach([$admin-\u003eid, $owner-\u003eid]);\n\n$user-\u003esyncRoles([$admin-\u003eid, $owner-\u003eid]);\n// equivalent to $user-\u003eroles()-\u003esync([$admin-\u003eid, $owner-\u003eid]);\n\n$user-\u003esyncRolesWithoutDetaching([$admin-\u003eid, $owner-\u003eid]);\n// equivalent to $user-\u003eroles()-\u003esyncWithoutDetaching([$admin-\u003eid, $owner-\u003eid]);\n```\n\n### Removal\n```php\n$user-\u003eremoveRole($admin); // parameter can be a Role object, array, id or the role string name\n// equivalent to $user-\u003eroles()-\u003edetach([$admin-\u003eid]);\n\n$user-\u003eremoveRoles([$admin, $owner]); // parameter can be a Role object, array, id or the role string name\n// equivalent to $user-\u003eroles()-\u003edetach([$admin-\u003eid, $owner-\u003eid]);\n```\n### User Permissions Assignment \u0026 Removal\nYou can give single permissions to a user, so in order to do it you only have to make:\n\n## Assignment\n```php\n$user-\u003egivePermission(['admin-create', 'admin-delete']); // parameter can be a Permission object, array, id or the permission string name\n\n$user-\u003esyncPermissions([$editUser-\u003eid, $createPost-\u003eid]);\n// equivalent to $user-\u003epermissions()-\u003esync([$editUser-\u003eid, createPost-\u003eid]);\n\n$user-\u003esyncPermissionsWithoutDetaching([$editUser, $createPost]); // parameter can be a Permission object, array or id\n    // equivalent to $user-\u003epermissions()-\u003esyncWithoutDetaching([$createPost-\u003eid, $editUser-\u003eid]);\n```\n\n# Middleware\n\n## Configuration\nThe middleware are registered automatically as role, permission. If you want to change or customize them, go to your config/gatekeeper.php and set the middleware.register value to false and add the following to the routeMiddleware array in app/Http/Kernel.php:\n```php\n'role' =\u003e \\Kettasoft\\Gatekeeper\\Middleware\\Role::class,\n'permission' =\u003e \\Kettasoft\\Gatekeeper\\Middleware\\Permission::class,\n```\n\n## Concepts\nYou can use a middleware to filter routes and route groups by permission, role:\n```php\nRoute::group(['prefix' =\u003e 'admin', 'middleware' =\u003e ['role:admin']], function() {\n    Route::get('/', 'AdminController@welcome');\n    Route::get('/manage', ['middleware' =\u003e ['permission:manage-admins'], 'uses' =\u003e 'AdminController@manageAdmins']);\n});\n```\nIf you use the pipe symbol it will be an OR operation:\n```php\n'middleware' =\u003e ['role:admin|root']\n// $user-\u003ehasRole(['admin', 'root']);\n\n'middleware' =\u003e ['permission:edit-post|edit-user']\n// $user-\u003ehasRole(['edit-post', 'edit-user']);\n```\nTo emulate AND functionality you can do:\n```php\n'middleware' =\u003e ['role:owner|writer,require_all']\n// $user-\u003ehasRole(['owner', 'writer'], true);\n\n'middleware' =\u003e ['permission:edit-post|edit-user,require_all']\n// $user-\u003eisAbleTo(['edit-post', 'edit-user'], true);\n```\n### Using Different Guards\n\nIf you want to use a different guard for the user check you can specify it as an option:\n```php\n'middleware' =\u003e ['role:owner|writer,require_all|guard:api']\n'middleware' =\u003e ['permission:edit-post|edit-user,guard:some_new_guard']\n```\n\n## Middleware Return\nThe middleware supports two types of returns in case the check fails. You can configure the return type and the value in the config/gatekeeper.php file.\n\n## Abort\nBy default the middleware aborts with a code 403 but you can customize it by changing the gatekeeper.middleware.handlers.abort.code value.\n\n## Redirect\nTo make a redirection in case the middleware check fails, you will need to change the middleware.handling value to redirect and the gatekeeper.middleware.handlers.redirect.url to the route you need to be redirected. Leaving the configuration like this:\n```php\n'handling' =\u003e 'redirect',\n'handlers' =\u003e [\n    'abort' =\u003e [\n        'code' =\u003e 403\n    ],\n    'redirect' =\u003e [\n        'url' =\u003e '/home',       // Change this to the route you need\n        'message' =\u003e [          // Key value message to be flashed into the session.\n            'key' =\u003e 'error',\n            'content' =\u003e ''     // If the content is empty nothing will be flashed to the session.\n        ]\n    ]\n]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkettasoft%2Fgatekeeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkettasoft%2Fgatekeeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkettasoft%2Fgatekeeper/lists"}