New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

whilesmart/eloquent-roles

Flexible roles and permissions package for Laravel applications
3,788 2
Install
composer require whilesmart/eloquent-roles
Latest Version:v1.0.1
PHP:^8.2
Laravel:11 · 12
License:MIT
Last Updated:Jul 15, 2026
Links: GitHub  ·  Packagist
Maintainer: whilesmart

Whilesmart Eloquent Roles

A flexible roles and permissions package for Laravel applications built on Eloquent ORM.

Latest Version on Packagist

Features

  • Contextual Roles: Assign roles within specific contexts (e.g., user can be admin in one workspace, member in another)
  • Hierarchical Permissions: Role-based permissions with inheritance support
  • Eloquent Integration: Seamlessly integrates with your existing Eloquent models
  • Flexible Architecture: Support for abilities, permissions, and role assignments
  • Laravel Auto-Discovery: Automatically registers service provider

Installation

Install the package via Composer:

composer require whilesmart/eloquent-roles

The package will automatically register its service provider.

Usage

Adding Roles to Models

Use the HasRoles trait on any model that should have roles:

use Whilesmart\Roles\Traits\HasRoles;

class User extends Model
{
    use HasRoles;
}

Role Management

// Check if user has a role
$user->hasRole('admin');

// Check role within specific context
$user->hasRole('manager', 'workspace', $workspaceId);

// Assign role
$user->assignRole($role);

// Assign role with context
$user->assignRole($role, 'workspace', $workspaceId);

Permission Management

Use the HasPermissions trait for permission-based access control:

use Whilesmart\Roles\Traits\HasPermissions;

class User extends Model
{
    use HasRoles, HasPermissions;
}
// Check permissions
$user->hasPermission('edit-posts');
$user->hasPermission('manage-users', 'workspace', $workspaceId);

Models

Role

  • name: Human-readable role name
  • slug: URL-friendly identifier (auto-generated)
  • description: Role description
  • level: Hierarchical level for role inheritance

Permission

  • name: Permission name
  • slug: URL-friendly identifier
  • description: Permission description

RoleAssignment

  • assignable: Polymorphic relation to any model
  • role_id: Associated role
  • context_type: Context model type (optional)
  • context_id: Context model ID (optional)

Configuration

The package works out of the box, but you can customize it by publishing the configuration:

php artisan vendor:publish --provider="Whilesmart\Roles\RolesServiceProvider"

Requirements

  • PHP ^8.2
  • Laravel ^11.0|^12.0

License

The MIT License (MIT).

Related Packages

micc83/rooles

A very simple roles and permissions manager for Laravel 5

1,617 11
usm4n/guardian

Role Based Access Control Package For Laravel With Backend Interface

1,083 17
lbausch/laravel-fortress

Roles and Permissions for Laravel's Authorization

745 6
santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

6,496,327 2,274
eneadm/ladder

Feather light permissions for Laravel.

27,347 263

Version History

Version Released PHP Laravel License
v1.0.1 ^8.2 ^11.0|^12.0 MIT
v1.0.0 ^8.2 ^11.0|^12.0 MIT