Download the PHP package lcloss/simple-permission without Composer
On this page you can find all versions of the php package lcloss/simple-permission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lcloss/simple-permission
More information about lcloss/simple-permission
Files in lcloss/simple-permission
Package simple-permission
Short Description Authorizations schema for Laravel projects
License MIT
Informations about the package simple-permission
SimplePermission
SimplePermission is a simple authorization package for Laravel. It is designed with Laravel 10, but may work with other versions. With this package, Roles and Permissions are added to your Laravel application, so you can easily manage authorization.
Installation
-
Install the package via composer:
-
Publish the config file:
-
Compile assets:
-
Run the migrations:
-
Add the
HasRolestrait to yourUsermodel: -
Add the
AuthGatesmiddleware to yourapp\Http\Kernel.phpfile: -
Add the
roleto theuserIf you are using Laravel Fortify, you can chane App\Actions\Fortify\CreateNewUser.php file:With the configuration above, the first user created will be a
sysadmin, and the others will beuser. - Other considerations
Check package blade files.
You can use your own blade files by replacing the blade file names in config/simple-permission.php file.
Do not forget to:
a) Add @liwewireStyles() and @livewireScripts() to your layout file. b) Add @yield('scripts') to your layout file. c) Add @yield('modals') to the end of body, on the layout file.
Configuration
You can change this package's configuration by editing the config/simple-permission.php file.
Database Seeder
This package comes with a database seeder that creates the default roles and permissions. You can run it with the following command:
Or, you can run individual seeders:
Roles and Permissions
Roles
This package cames with default roles: 'sysadmin', 'admin', 'premium-user', 'user' and 'free-user'.
Each role has a single identification slug and a level to determine the role's hierarchy.
Roles with level 1 are the highest level roles, and roles with level 300 are the lowest level roles.
All roles with level 1 get access to all permissions.
You can customize the roles by editing the database\seeders\SimplePermissionRoleSeeder.php file.
Permissions
Permissions follows the structure of access, list and CRUD operations (create, read, update and delete).
Tipically access permisison is used to allow access to a resource, list permission is used to allow listing the resource, and CRUD permissions are used to allow operations on the resource.
A permission is composed by an object and an action, delimited by a _ character.
An object is a resource, like users, roles, permissions, posts or comments.
An action is an operation on the resource, like access, list, create, read, update or delete.
So, the permission users_create determine if the user can create users, and the permission users_list determine if the user can list users.
You can customize the permissions by editing the database\seeders\SimplePermissionPermissionSeeder.php file.
To protect a route, you can use the can middleware:
To protect a controller method, you can use the can middleware:
To protect a part of a view, you can use the @can directive:
TODOs
- [ ] Add tests
- [ ] Add artisan commands