PHPackages                             mitul456/laravel-multi-role-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. mitul456/laravel-multi-role-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

mitul456/laravel-multi-role-auth
================================

A comprehensive multi-role authentication system for Laravel

v1.0.0(3mo ago)01MITPHP ^8.1

Since Apr 17Compare

[ Source](https://github.com/mitul456/laravel-multi-role-auth)[ Packagist](https://packagist.org/packages/mitul456/laravel-multi-role-auth)[ RSS](/packages/mitul456-laravel-multi-role-auth/feed)WikiDiscussions Synced 3w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Laravel Multi-Role Authentication Package
=========================================

[](#laravel-multi-role-authentication-package)

[![Laravel Version](https://camo.githubusercontent.com/7dca8b1cdf581438021b806542ff584f485c97d2afe671c0cf4c3f851b370817/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825323025374325323031312e7825323025374325323031322e782d726564)](https://camo.githubusercontent.com/7dca8b1cdf581438021b806542ff584f485c97d2afe671c0cf4c3f851b370817/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825323025374325323031312e7825323025374325323031322e782d726564)[![PHP Version](https://camo.githubusercontent.com/83dd395020c37276225039739320f6c8e7e99963ab21ee3d09282cb48dad2a60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c7565)](https://camo.githubusercontent.com/83dd395020c37276225039739320f6c8e7e99963ab21ee3d09282cb48dad2a60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c7565)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)[![Downloads](https://camo.githubusercontent.com/b78482d422b0f689087f98aa77dc6f6074d6b5b962590ba1519f6f91123e60b6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f776e6c6f6164732d316b2532422d627269676874677265656e)](https://camo.githubusercontent.com/b78482d422b0f689087f98aa77dc6f6074d6b5b962590ba1519f6f91123e60b6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f776e6c6f6164732d316b2532422d627269676874677265656e)

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

---

📋 Table of Contents
-------------------

[](#-table-of-contents)

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

---

✨ Features
----------

[](#-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
--------------

[](#-requirements)

- PHP &gt;= 8.1
- Laravel 10.x / 11.x / 12.x
- Composer (latest)
- Supported DB: MySQL, PostgreSQL, SQLite, SQL Server

---

🚀 Quick Start
-------------

[](#-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)
--------------------------

[](#️-installation-detailed)

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

(Optional)

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

---

⚙️ Configuration
----------------

[](#️-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
-------------

[](#-usage-guide)

### Assign Role

[](#assign-role)

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

### Check Role

[](#check-role)

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

### Middleware

[](#middleware)

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

### Blade

[](#blade)

```
@role('admin')
    Admin only
@endrole
```

### Permission

[](#permission)

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

---

🎯 Dynamic Role Management
-------------------------

[](#-dynamic-role-management)

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

$user->assignRole('Manager');

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

---

⌨️ Artisan Commands
-------------------

[](#️-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
------------------

[](#-helper-functions)

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

---

🧪 Testing
---------

[](#-testing)

```
php artisan test
```

---

🔧 Troubleshooting
-----------------

[](#-troubleshooting)

```
php artisan optimize:clear
composer dump-autoload
```

---

🔒 Security Tips
---------------

[](#-security-tips)

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

---

📄 License
---------

[](#-license)

MIT License

---

Made with ❤️ by Mitul

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance81

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

99d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e75026c0db645c84708f358ff39afa8c866129ea9b8df2e7c7ce1b1bf59f7d8b?d=identicon)[mitul456](/maintainers/mitul456)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mitul456-laravel-multi-role-auth/health.svg)

```
[![Health](https://phpackages.com/badges/mitul456-laravel-multi-role-auth/health.svg)](https://phpackages.com/packages/mitul456-laravel-multi-role-auth)
```

###  Alternatives

[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3518.3k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
