Download the PHP package lazycode/laravel-simple-permissions without Composer
On this page you can find all versions of the php package lazycode/laravel-simple-permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lazycode/laravel-simple-permissions
More information about lazycode/laravel-simple-permissions
Files in lazycode/laravel-simple-permissions
Package laravel-simple-permissions
Short Description A Laravel package for handling roles and permissions.
License MIT
Informations about the package laravel-simple-permissions
Laravel Simple Permissions
A simple Laravel package for handling roles and permissions. This package allows you to assign roles to users, manage permissions, and easily check for roles and permissions in your application.
Installation
To install the package, run the following command:
Publish Configuration
After installing the package, publish the configuration file using:
Run Migrations
Next, run the migrations to create the necessary tables in your database:
Usage
Setting Up the User Model
In your User model (usually located at app/Models/User.php), ensure you include the HasRolesAndPermissions trait:
Assigning Roles and Permissions
You can now use the package's functionality in your application. Here are some examples:
Assign a Role
To assign a role to a user:
Get User's Role
To get the user's assigned role:
Check User's Permissions
To check if a user has a specific permission:
Functions List
role
: Return the Role collection of modal.hasRole
@hasRole
: Check Loggedin User has the role.hasAnyRole
@hasAnyRole
: Checks if the user has any of the specified roles.permission
: Get the permission collection from permission modal.@hasPermission
@haspermission
: Check Loggedin user has the permission.hasAnyPermission
@hasAnyPermission
: Checks if the user has any of the specified permissions.hasAllPermission
@hasAllPermission
: Verifies that the user has all the specified permissions.hasExactPermissions
@hasExactPermissions
: Checks if the user has exactly the specified permissions.
Seeding Roles and Permissions
You can create a seeder to start with some default roles and permissions. For example:
Database Schema
Ensure your database schema is set up correctly. The following tables should exist:
roles
: To store roles.permissions
: To store permissions.role_permission
: Pivot table to manage many-to-many relationships between roles and permissions.users
: Ensure there is arole_id
column in theusers
table to associate users with their roles.
Conclusion
This package provides a simple way to manage user roles and permissions in your Laravel application. For further customization or additional features, feel free to contribute or reach out for support.