Download the PHP package kettasoft/gatekeeper without Composer
On this page you can find all versions of the php package kettasoft/gatekeeper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kettasoft/gatekeeper
More information about kettasoft/gatekeeper
Files in kettasoft/gatekeeper
Package gatekeeper
Short Description A lightweight and powerful package for handling permissions and provisions in Laravel
License MIT
Informations about the package gatekeeper
Gatekeeper
This 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.
Installation
You can install the package using composer:
In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework, you must install the service provider:
publish the config/gatekeeper.php config
WARNING
If this command did not publish any files, chances are, the Laratrust service provider hasn't been registered. Try clearing your configuration cache
Run the setup command:
IMPORTANT: Before running the command go to your config/gatekeeper.php file and change the values according to your needs.
This command will generate the migrations, create the Role and Permission models
Dump the autoloader:
Run the migrations:
Roles & Permissions
Setting things up
Let's start by creating the following Roles:
Role Assignment & Removal:
Removal
User Permissions Assignment & Removal
You can give single permissions to a user, so in order to do it you only have to make:
Assignment
Middleware
Configuration
The 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:
Concepts
You can use a middleware to filter routes and route groups by permission, role:
If you use the pipe symbol it will be an OR operation:
To emulate AND functionality you can do:
Using Different Guards
If you want to use a different guard for the user check you can specify it as an option:
Middleware Return
The 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.
Abort
By default the middleware aborts with a code 403 but you can customize it by changing the gatekeeper.middleware.handlers.abort.code value.
Redirect
To 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: