xrazerz / rbac
Create a Comprehensive RBAC System For Laravel that allows for more granular control over user permissions
Requires
- illuminate/database: ^12.0@dev
- xrazerz/rbac: dev-main@dev
This package is auto-updated.
Last update: 2025-04-28 01:06:21 UTC
README
Table of Contents
Introduction
This package provides a comprehensive Role-Based Access Control (RBAC) system for Laravel, allowing for more granular control over user permissions. It is designed to be flexible and easy to integrate into your Laravel application.
Features
- Define roles and permissions.
- Assign roles to users.
- Check user permissions easily.
- Middleware for route protection.
- Artisan commands for managing roles and permissions.
Installation
-
Install the package via Composer:
composer require xrazerz/laravel-rbac
-
Publish the configuration file and migrations:
php artisan vendor:publish --provider="Dev\Rabc\Providers\RabcServiceProvider"
-
Run the migrations:
php artisan migrate
Configuration
After publishing the configuration file, you can find it at config/rbac.php
. Customize it according to your needs.
Usage
Defining Roles and Permissions
You can define roles and permissions in your database or using the provided Artisan commands.
# Create a role php artisan rbac:create-role admin # Create a permission php artisan rbac:create-permission view-dashboard
Assigning Roles to Users
You can assign roles to users using the assignRole
method.
$user = User::find(1); $user->assignRole('admin');
Checking Permissions
You can check if a user has a specific permission using the can
method.
if ($user->can('view-dashboard')) { // The user can view the dashboard }
Middleware
You can protect your routes using the provided middleware.
Route::group(['middleware' => ['role:admin']], function () { Route::get('/admin', 'AdminController@index'); });
Contributing
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
Ismail Mohamed - xrootedx.dev@gmail.com
Project Link: https://github.com/xrazerz/laravel-rbac