xrazerz/rbac
Composer 安装命令:
composer require xrazerz/rbac
包简介
Create a Comprehensive RBAC System For Laravel that allows for more granular control over user permissions
README 文档
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
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-27