Download the PHP package enea/laravel-authorization without Composer
On this page you can find all versions of the php package enea/laravel-authorization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download enea/laravel-authorization
More information about enea/laravel-authorization
Files in enea/laravel-authorization
Package laravel-authorization
Short Description Package to manage the permissions in a laravel application
License MIT
Informations about the package laravel-authorization
Laravel Authorization
Laravel Authorization is a package that provides a simple administration interface for roles and permissions.
Table of Contents
- Installation
- Quick Start
- checks
GRANT
REVOKE
DENY
- Middleware
- Blade Directives
Installation
Laravel Authorization requires PHP 8.1. This version supports Laravel 10 only.
To get the latest version, simply require the project using Composer:
Once installed, if you are not using automatic package discovery, then you need to register
the Enea\Authorization\AuthorizationServiceProvider
service provider in your config/app.php
.
and finally, it only remains to run in the console:
Quick Start
Starting with laravel-authorization is as simple as extending the User
model that provides the package:
Or in case you need to customize your user model, you must implement the Enea\Authorization\Contracts\Authorisable
interface and use
the Enea\Authorization\Traits\Authorisable
trait:
Checks
There are some methods available for checking roles and permissions:
Method | Parameter | Return |
---|---|---|
can | permission-name | boolean |
cannot | permission-name | boolean |
isMemberOf | role-name | boolean |
isntMemberOf | role-name | boolean |
Example
On the other hand, a role can only have permissions:
GRANT
Simplify the way in which roles and permissions are granted, both can be granted through the grant
method in your model, you can see an
example here
REVOKE
To revoke a permission or role of a model, you must use the revoke
or revokeMultiple
method:
DENY
To prohibit certain accesses to a user can do it through the method deny
and denyMultiple
:
Middleware
The middleware are activated automatically from the beginning, to change this you can do it from the configuration file:
Or in case you want to do a manual configuration you can deactivate the automatic load and modify your kernel file:
Then you can use it in your routes like any other middleware:
In case any user tries to access a protected route without authorization, an exception of
type UnauthorizedOwnerException
will be
throw.
Custom errors
To show a custom error, we can edit
the Handler
file:
Blade Directives
This package also adds Blade directives to verify if the currently connected user has a specific role or permission.
Optionally you can pass in the guard
that the check will be performed on as a second argument.
For Roles
and to deny
For Permissions
and to deny
Examples
Changelog
Please see CHANGELOG for more information what has changed recently.
License
Laravel Authorization is licensed under The MIT License (MIT).