buglock / rolepermissionmodule
A Role and Permission manement module
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/buglock/rolepermissionmodule
This package is not auto-updated.
Last update: 2025-12-22 18:22:44 UTC
README
BugLocks is a modular Laravel package to manage user roles and permissions. It includes ready-to-use views, blade directives, route protection, middleware integration, and publishing support for easy customization.
📘 What is BugLocks?
BugLocks is a powerful Laravel package designed for Role & Permission management. It provides built-in UI, blade directives, database migrations, and middleware to simplify access control in Laravel applications.
🚀 Features
- Access Control: Secure your routes, pages, and actions using roles, permissions, and middleware.
- Simple DB Structure: Built-in tables for users, roles, and permissions ready for immediate use.
- UI Ready: Includes customizable views for login, error pages, and permission management.
🛠 Built With
- Laravel 9 / 10
- PHP 8+
- Bootstrap 5.3
🔧 Installation
Step 1: Requirements
- ✅ PHP 8.1 or above
- ✅ Laravel 10+
- ✅ Composer installed globally
- ✅ MySQL/PostgreSQL setup
Step 2: Install via Composer
composer require buglock/rolepermissionmodule
Step 3: Publish Config, Model & Views
php artisan vendor:publish --tag=buglocks-config php artisan vendor:publish --tag=role-permissions-models php artisan vendor:publish --tag=buglocks-error-views
Step 4: Run Migrations
php artisan migrate
Step 5: Optional Configuration
Edit the config file at:
config/buglocks.php
🔐 Role & Permission Management
Initialize BugLock
use BugLock\rolePermissionModule\Http\Controllers\BugLock; $bugLock = new BugLock();
Create Roles
$bugLock->createRole('admin'); $bugLock->createRole('admin', 'editor', 'user');
Create Permissions
$bugLock->createPermission('edit'); $bugLock->createPermission('edit', 'view');
🔗 Auto & Manual Role-Permission Assignment
Auto Assignment
$bug_lock = new BugLock(); $bug_lock->createRole('admin-1', 'admin-2'); $bug_lock->createPermission('edit-resume-1', 'remove-resume-2'); $bug_lock->assignedLocks(); dd($bug_lock);
Manual Assignment
$bug_lock = new BugLock(); $bug_lock->createRole('admin-1', 'admin-2'); $bug_lock->createPermission('edit-resume-1', 'remove-resume-2'); $bug_lock->assignedLocks( ['Admin'], ['delete','invite'] ); dd($bug_lock);
Configure User Model
namespace App\Models; use BugLock\rolePermissionModule\Models\UserRoles; use BugLock\rolePermissionModule\traits\assignBugLock; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use assignBugLock; }
Assign Role to User
$user = User::where('name','coder 1')->first(); $user->assignRoleToUser('admin'); $user->assignRoleToUser('manager'); if($user->fails){ dd($user->reason); }
🧩 Authentication Middleware
1. Check Login
Route::group(['middleware' => ['buglock.auth:web,view,no']], function () { Route::get('/dash-1', [TestController::class, 'dash_1']); }); Route::group(['middleware' => ['buglock.auth:web,view,yes']], function () { Route::get('/dash-1', [TestController::class, 'dash_1']); });
2. Check Role
Route::group(['middleware' => ['buglock.role:web,view,admin,employee']], function () { Route::get('/dash', [TestController::class, 'dash']); }); Route::group(['middleware' => ['buglock.role:web,view,manager']], function () { Route::get('/dash', [TestController::class, 'dash']); });
3. Check Permission
Route::group(['middleware' => ['buglock.permission:web,view,edit,delete']], function () { Route::get('/dash-3', [TestController::class, 'dash_3']); }); Route::group(['middleware' => ['buglock.permission:web,view,view']], function () { Route::get('/dash-3', [TestController::class, 'dash_3']); });
🧩 Blade Views
The package includes 3 blade templates for error handling. Customize them by publishing the views:
View Files
- 🔒 auth.blade.php - Shown when the user is not logged in.
- 🧑💼 role.blade.php - Shown when the user does not have the required role.
- 🔑 permissions.blade.php - Shown when the user lacks required permission.
Publish Views
php artisan vendor:publish --tag=buglocks-error-views
After publishing, customize in:
resources/views/vendor/buglock/