Looking to hire Laravel developers? Try LaraJobs
This package is not available.

laravel-multi-role-auth maintained by mitul456

Description
A comprehensive multi-role authentication system for Laravel
Last update
2026/04/17 05:50 (dev-main)
License
Links
Downloads
1

Comments
comments powered by Disqus

Laravel Multi-Role Authentication Package

Laravel Version PHP Version License Downloads

A powerful, flexible, and production-ready multi-role authentication system for Laravel applications.


📋 Table of Contents

  • Features
  • Requirements
  • Quick Start
  • Installation
  • Configuration
  • Usage Guide
  • Dynamic Role Management
  • Artisan Commands
  • Helper Functions
  • Testing
  • Troubleshooting
  • Security
  • License

✨ Features

  • 🎭 Unlimited Roles
  • 📊 Role Hierarchy (priority-based)
  • 🔐 Permission-based access control
  • 🛡️ Multi-Guard Support (web, api)
  • 🎯 Smart role-based redirects
  • 🚀 Middleware protection (role:admin)
  • 🎨 Blade directives (@role, @hasrole)
  • 📱 API ready
  • 🎛️ Admin panel support
  • ⌨️ Artisan commands

📦 Requirements

  • PHP >= 8.1
  • Laravel 10.x / 11.x / 12.x
  • Composer (latest)
  • Supported DB: MySQL, PostgreSQL, SQLite, SQL Server

🚀 Quick Start

composer require mitul456/laravel-multi-role-auth
php artisan multirole:install
php artisan migrate

Add trait to User model:

use LaravelMultiRoleAuth\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}

⚙️ Installation (Detailed)

composer require mitul456/laravel-multi-role-auth
php artisan multirole:install

(Optional)

php artisan vendor:publish --tag=multirole-config

⚙️ Configuration

config/multirole.php

return [
    'default_role' => 'User',

    'role_hierarchy' => [
        'SuperAdmin',
        'Admin',
        'Moderator',
        'Editor',
        'User',
    ],

    'redirect_paths' => [
        'SuperAdmin' => '/superadmin/dashboard',
        'Admin' => '/admin/dashboard',
        'default' => '/dashboard',
    ],
];

📖 Usage Guide

Assign Role

$user->assignRole('Admin');
$user->syncRoles(['Editor', 'Moderator']);

Check Role

$user->hasRole('Admin');
$user->hasRole(['Admin', 'SuperAdmin']);

Middleware

Route::middleware(['auth', 'role:Admin'])->group(function () {
    //
});

Blade

@role('admin')
    <p>Admin only</p>
@endrole

Permission

$user->can('edit-articles');

🎯 Dynamic Role Management

Role::create(['name' => 'Manager']);

$user->assignRole('Manager');

if ($user->hasRole('Manager')) {
    //
}

⌨️ Artisan Commands

php artisan multirole:install
php artisan role:create "Manager"
php artisan role:assign 1 "Admin"
php artisan role:sync 1 "Editor" "Moderator"

🔧 Helper Functions

hasRole($user, 'Admin');
currentUserRole();
canPerform('manage-users');

🧪 Testing

php artisan test

🔧 Troubleshooting

php artisan optimize:clear
composer dump-autoload

🔒 Security Tips

  • Always use middleware
  • Avoid client-side role checks
  • Use permissions for sensitive actions

📄 License

MIT License