PHPackages                             luizhenriqueferreira/laravel-acl - 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. luizhenriqueferreira/laravel-acl

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

luizhenriqueferreira/laravel-acl
================================

ACL package for Laravel

v1.1(5y ago)09MITPHPPHP ^7.2.5

Since Oct 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/luizhenriqueferreira/laravel-acl)[ Packagist](https://packagist.org/packages/luizhenriqueferreira/laravel-acl)[ RSS](/packages/luizhenriqueferreira-laravel-acl/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (7)Versions (4)Used By (0)

Laravel Acl package v1.0
========================

[](#laravel-acl-package-v10)

Laravel Acl is a PHP package for Laravel Framework, used for manipulation of access control list. Package is providing an easier way to control roles and permissions of users on your site.

Requirements
------------

[](#requirements)

- PHP &gt;=7.0

Install
-------

[](#install)

1. Type next command in your terminal:

```
composer require luizhenriqueferreira/LaravelAcl
```

2. Add the service provider to your config/app.php file in section providers:

> Laravel 5.5 uses Package Auto-Discovery, so does not require you to manually add the ServiceProvider.

```
'providers' => [
    // ...
    LuizHenriqueFerreira\LaravelAcl\LaravelAclServiceProvider::class,
    // ...
],
```

3. Run the migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Use the following traits on your User model:

[](#use-the-following-traits-on-your-user-model)

```
// ...

use LuizHenriqueFerreira\LaravelAcl\Models\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;

    // ... Your User Model Code
}
```

### Using in code

[](#using-in-code)

Check role

```
if ($user->hasRoles'('admin')) {
    // User is admin
}
// or
if ($user->hasRoles('admin', 'writer')) {
    // User is admin or writer
}
// or
if ($user->hasRoles(['admin', 'writer'])) {
    // User is admin or writer
}
```

Attach role

```
$user->attachRoles(1);

//or
$user->attachRoles('admin');

//or
$user->attachRoles(Role::find(1));

//or
$user->attachRoles(1, 2);

//or
$user->attachRoles('admin', 'writer');

//or
$user->attachRoles(Role::find(1), Role::find(2));

//or
$user->attachRoles(1, 'writer', Role::find(3));

//or
$user->attachRoles([1]);

//or
$user->attachRoles(['admin']);

//or
$user->attachRoles([Role::find(1)]);

//or
$user->attachRoles([1, 2]);

//or
$user->attachRoles(['admin', 'writer']);

//or
$user->attachRoles([Role::find(1), Role::find(2)]);

//or
$user->attachRoles([1, 'writer', Role::find(3)]);
```

The same function, Detach role

```
$user->detachRoles('writer');
// ...
$user->detachRoles(2, 'writer', Role::find(2));
// ...
$user->detachRoles([2, 'writer', Role::find(2)]);
```

Clear all roles

```
$user->detachRoles();
```

Check permission

```
if ($user->hasPermissions('create-post')) {
    // User has permission "create post"
}
// or
if ($user->hasPermissions('create-post', 'update-post')) {
    // User has permission "create post" or "update post"
}
// or
if ($user->hasPermissions(['create-post', 'update-post'])) {
    // User has permission "create post" or "update post"
}
```

Attach permissions

```
$role->attachPermissions(1);

//or
$role->attachPermissions('create-post');

//or
$role->attachPermissions(Permission::find(1));

//or
$role->attachPermissions(1, 2);

//or
$role->attachPermissions('create-post', 'update-post');

//or
$role->attachPermissions(Permission::find(1), Permission::find(2));

//or
$role->attachPermissions(1, 'update-post', Permission::find(3));

//or
$role->attachPermissions([1]);

//or
$role->attachPermissions(['create-post']);

//or
$role->attachPermissions([Permission::find(1)]);

//or
$role->attachPermissions([1, 2]);

//or
$role->attachPermissions(['create-post', 'update-post']);

//or
$role->attachPermissions([Permission::find(1), Permission::find(2)]);

//or
$role->attachPermissions([1, 'update-post', Permission::find(3)]);
```

The same function, Detach permissions

```
$role->detachPermissions('create-post');
// ...
$role->detachPermissions(1, 'update-post', Permission::find(3));
// ...
$role->detachPermissions([1, 'update-post', Permission::find(3)]);
```

Clear all permissions

```
$role->detachPermissions();
```

See the code for more information... =)

### Using blade directives

[](#using-blade-directives)

You also can use directives to verify the currently logged in user has any roles or permissions.

Check roles:

```
@hasroles('admin')

@elsehasrole('writer')

@else

@endrole
```

or check more roles in one directive:

```
 @hasroles(['admin', 'writer'])

 @endhasrole
```

Check permissions:

```
@can('create-post')

@elsecan('edit-post')

@endcan
```

### Using middlewares

[](#using-middlewares)

You can use role middleware for check access to some routes

```
Route::middleware(['role:admin'])->group(function() {

    // Only for user with role admin
    Route::get('/admin', function() {
        // some code
    });

});
```

also you can use permission middleware

```
Route::middleware(['permission:create-post'])->group(function() {

    // Only for user with permission create post
    Route::get('/admin/post', function() {
        // some code
    });

});
```

or use role and permission middleware together

```
Route::middleware(['role:admin,moderator', 'permission:remove-post'])->group(function() {

    // Only for user with role moderator and with permission create post
    Route::get('/admin/post/remove', function() {
        // some code
    });

});
```

License
-------

[](#license)

Laravel Acl package is licensed under the [MIT License](http://opensource.org/licenses/MIT).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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 ~139 days

Total

2

Last Release

1852d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b68173114ce35c2ae1883ea99bcd82732dd361734889f1bb3dc0da7418fe7d5?d=identicon)[Luiz Henrique](/maintainers/Luiz%20Henrique)

---

Top Contributors

[![luizhenriqueferreira](https://avatars.githubusercontent.com/u/30929047?v=4)](https://github.com/luizhenriqueferreira "luizhenriqueferreira (9 commits)")

---

Tags

laravellaravel 6laravel 7laravel 8securityauthaclpermissionlaravel 5roleLuiz Henrique ferreira

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/luizhenriqueferreira-laravel-acl/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[efficiently/authority-controller

AuthorityController is an PHP authorization library for Laravel 5 which restricts what resources a given user is allowed to access.

15533.2k](/packages/efficiently-authority-controller)[wnikk/laravel-access-rules

Simple system of ACR (access control rules) for Laravel, with roles, groups, unlimited inheritance and possibility of multiplayer use.

103.6k1](/packages/wnikk-laravel-access-rules)

PHPackages © 2026

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