PHPackages                             leoche/laravel-lpermissions - 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. leoche/laravel-lpermissions

ActiveLaravel-package

leoche/laravel-lpermissions
===========================

Users Roles &amp; Permissions for routes

1.0.4(9y ago)359MITPHPPHP &gt;=5.5.9

Since Apr 10Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Leoche/laravel-lpermissions)[ Packagist](https://packagist.org/packages/leoche/laravel-lpermissions)[ RSS](/packages/leoche-laravel-lpermissions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

[![](./lpermissions-logo.png)](./lpermissions-logo.png)

[![Laravel](https://camo.githubusercontent.com/891fa466c47ca07f106dfc405bb0b5914b1627c0539dc2703d020e2342f6bb61/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e332d7265642e7376673f7374796c653d666c6174)](https://laravel.com/docs/5.3)[![Source](https://camo.githubusercontent.com/ca9e256690c5059261b9e91378125023a3087e93c2d39fcdb6671103a33c8f2a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f536f757263652d6c656f6368652f6c7065726d697373696f6e732d677265656e2e7376673f7374796c653d666c6174)](https://github.com/leoche/laravel-lpermissions/)[![License](https://camo.githubusercontent.com/c2dc14986df477c49656fdf4f44087887e2d2df31ab8f59514eccb48eedef645/687474703a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](https://tldrlegal.com/license/mit-license)

Laravel LPermissions adds roles and permissions to Auth Laravel 5.3. Protect your routes and your views.

### Table of Contents

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Methods Usage](#methods)
- [Routes Usage](#routes)
- [Blades Usage](#blades)
- [Example](#example)
- [Todo](#todo)

### Requirements

[](#requirements)

- This package requires PHP 5.5+
- This package requires Laravel 5.3

Installation
----------------------------------------------------

[](#installation)

**1.** Require the package in your `composer.json` and update your dependency with `composer update`:

```
"require": {
...
"leoche/laravel-lpermissions": "1.0",
...
},

```

**2.** Add the package to your application service providers in `config/app.php`.

```
'providers' => [
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
...
Leoche\LPermissions\LPermissionsServiceProvider::class,

],
```

**3.** Publish the package migrations to your application and run these with `php artisan migrate`.

```
$ php artisan vendor:publish --provider="Leoche\LPermissions\LPermissionsServiceProvider"

```

**4.** Add the middleware to your `app/Http/Kernel.php`.

```
protected $routeMiddleware = [

....
'permission' => \Leoche\LPermissions\Middleware\checkPermission::class,

];
```

**5.** Add the HasRole trait to your `User` model.

```
use Leoche\LPermissions\Traits\HasRole;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, HasRole;
}
```

Methods Usage
------------------------------------------------

[](#methods-usage)

#### Roles

[](#roles)

Creating roles

```
$role = new Role();
$role->name = 'Admin';
//The slug will be automatically generated from the role name
$role->save();
```

Assign or Remove a role

```
$user = User::find(1);
$user->setRole(2); // with id
//OR
$user->setRole("Admin"); // with slug/name
$user->removeRole();
```

Assign or remove an inherit role to a role

```
$role = Role::find(1);
$role->setInheritRole(2); //with id
//OR
$role->setInheritRole("Admin");
$role->removeInheritRole();
```

Assign or remove a permission to a role or a user

```
$role = Role::find(1);
$role->setPermission("admin/*", "*");
$role->removePermission("/admin/*", "*");

$user = User::find(1);
$user->setPermission("secretpage", "GET");
$user->removePermission("secretpage", "GET");

$user = User::find(1);
$user->removeAllPermissions(); //delete all permissions of user
$user->getRole->removeAllPermissions(); //delete all permissions of user's role

$role = Role::find(1);
$role->removeAllPermissions();
```

Notes : LPermissions parse permissions path as:

Given PathParsed pathhome/home/blog/:slugblog/:slugblog/:alpha/blog/:alpha/blog/:number/comments/blog/:number/commentsGiven keysRegex`*`(.\*?)`:number`(\\d\*?)`:alpha`(\[A-z\]\*?)`:alphanum`(\[A-z0-9\]\*?)`:slug`(\[A-z0-9-\_\]\*?)Routes Usage
----------------------------------------------

[](#routes-usage)

You just have to specifythe middleware to the group route. It will check for permission and abort 401 if unauthorised

```
Route::get('/home', function () {
	return "You can go here";
});
...
Route::group(['middleware' => ['auth']], function () {
	Route::get('/home1', function () {
		return "You can go here if you're logged";
	});
});
...
Route::group(['middleware' => ['permission']], function () {
	Route::get('/home2', function () {
		return "You can go here if you or your role have '/home2' or '/*' permission";
	});
});
...
Route::group(['middleware' => ['auth','permission']], function () {
	Route::get('/home3', function () {
		return "You can go here if you're logged and you or your role have '/home3' or '/*' permission";
	});
});
```

Blades Usage
----------------------------------------------

[](#blades-usage)

In your blades view you can use directives to show something (eg: links, infos) only if the user has the permission or the role

```
@permission('admin/dashboard')
 //Only shown to users who can access to admin dashboard
@endpermission
...
@permission('admin/posts','post')
 //Only shown to users who can access to admin posts with method POST
@endpermission
...

...
@role('moderator')
 //Only shown to moderators role
@endrole
...
@role('*')
 //Has any roles
@else
 //Has no role (Eg: role_id=0)
@endrole
```

Example
------------------------------------------

[](#example)

Users Table

idusernamerole\_id1Mike02Lisa13John2Roles Table

idinherit\_idname11Admin20MemberPermissions Table

idroutemethoduser\_idrole\_id1/admin/\*\*012/account/\*GET023/secretGET10Route web.php

```
Route::get('/', function () {
	return "home ppage";
});

Route::group(['middleware' => ['auth','permission']], function () {
	Route::get('/secret', function () {
		return "SECRET PAGE";
	});
	Route::get('/account', function ($id) {
		return "view account infos";
	});
});

Route::group(["prefix" => "admin",'middleware' => ['auth','permission']], function () {
	Route::get('/', function () {
		return view('dashboard');
	});
	Route::ressource('posts', 'PostController');
});
```

Everyone can see the homepage

Only mike can view /secret

Lisa can do anything in /admin/\* and view account pages (inherit from members)

John can only view accounts pages

Todo
------------------------------------

[](#todo)

- Function to assign/revoke role to users
- Function to assign/revoke permission to role
- Function to inherit role to role

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~1 days

Total

5

Last Release

3316d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1abc6cb98b7e6d5c8238b0bc53599307e0f9c52a32e7001ff889e55556ea1503?d=identicon)[Leoche](/maintainers/Leoche)

---

Top Contributors

[![Leoche](https://avatars.githubusercontent.com/u/1678699?v=4)](https://github.com/Leoche "Leoche (32 commits)")

### Embed Badge

![Health badge](/badges/leoche-laravel-lpermissions/health.svg)

```
[![Health](https://phpackages.com/badges/leoche-laravel-lpermissions/health.svg)](https://phpackages.com/packages/leoche-laravel-lpermissions)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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