Download the PHP package aammui/role-permission without Composer
On this page you can find all versions of the php package aammui/role-permission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aammui/role-permission
More information about aammui/role-permission
Files in aammui/role-permission
Package role-permission
Short Description Role permission system for laravel
License MIT
Informations about the package role-permission
Introduction and Core Concepts
Content
Introduction
Role
Role can be used to define a group of permission. If a user has a editor role, he/she can edit, delete, publish articles. I prefer to use role in most of the cases to allow a group of action.
- Roles are case insensetive. and has same meaning.
- Roles not need to create explicitly. This function creats a new role admin if the given role is not created yet in the database, and then the given role is assign to the given user.
To add permission to role
To attach a CRUD of permission to Role.
It will add create article, read article, update article, delete article permission to the given role.
Permission
Permission can be used to deny a particular action. I assume in most of the cases the actions are associated with roles. So, if read, write, delete article action is associated with a Editor role, then you can deny Editor to delete article by:
Middleware
Use either permission or role as a middleware to protect the resources. Use |
to use multiple role or permission in a middleware. If both role and permission middleware are defined both middleware should passed to access the resources. Here, you can deny to publish a article even he has got a editor role.
Add middlewire in the route middlewire section.
Use Middlewire in anywhere
above can interpret as user should have sytem admin or database admin role and read article permission is not denied.
Installation
Laravel Compatibility
Laravel Version | Role Permission Version | Installation |
---|---|---|
9.x | 3.0.0 | |
8.x | 2.0.0 | |
7.x | 1.0.0 | |
6.x, 5.x | 0.7 |
Publish the assests and run migrations
Uses
Use a trait to your user model.
and then following api are available to you.
-
This sync the roles, if a user has admin role and then you send only editor, it will remove admin role and then user will only have editor role. Send all roles to update the roles.
-
It returns roles in array.
Exception
It throws following exception as below. | Exception | Remarks |
---|---|---|
User is not logged in yet. | ||
A function or route is protected by a role, and logged in user doesn't have that role yet. |
UseCase: Exception uses for user redirection.
Suppose we want to redirect not logged in user to login page, which can be done using handling exception in class. The purpose of this exception make available is to support full customization. For example you may want to redirect to login page for that user whom don't have right role, or you simply only want to show 403 page.
All versions of role-permission with dependencies
illuminate/auth Version ^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/database Version ^7.0|^8.40|^9.0|^10.0|^11.0