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

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

nematollahi/laravel-acl
=======================

you can used from acl ( access control list ) in laravel

v1.1.1(1y ago)114MITPHP

Since Jun 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mohammadNematollahi/Laravel-ACL)[ Packagist](https://packagist.org/packages/nematollahi/laravel-acl)[ RSS](/packages/nematollahi-laravel-acl/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (4)Used By (0)

### hello everybody this is acl ( access control list ) for laravel 😃

[](#hello-everybody-this-is-acl--access-control-list--for-laravel-)

\[Getting Started\]
===================

[](#getting-started)

1- Install the package using composer

```
composer require nematollahi/laravel-acl
```

2- Publish the package configuartion files and add your own models to the list of ACL models

```
php artisan vendor:publish --provider Nematollahi\ACL\ACLServiceProvider
```

- The items that are added are:

    1- added acl.php into folder config

    2- added acl into folder middleware

    3- added required migrations in the migration folder

    4- added role and permission model

3- migrate

```
php artisan migrate
```

4- trait HasACLTools into model user

```
//app/Models/User.php

use Nematollahi\ACL\Traits\HasACLTools;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable , HasACLTools;

enother codes ...
```

5- add acl middleware to kernal

```
//app/Http/Kernel.php

'acl' => \App\Http\Middleware\ACL::class,
```

6- call acl in provider

```
//app/Providers/AppServiceProvider.php

use Nematollahi\ACL\ACL;

ACl::run();
```

7- use in route

```
//routes/web.php

Route::get('/', function () {
    return view('welcome');
})->middleware("acl:admin");
```

how we can use permission in project
------------------------------------

[](#how-we-can-use-permission-in-project)

- Databases Required for This Section ( permissions , permissions\_user )
- [![Watch the video]()](https://drive.google.com/file/d/13D2bB8IAeb1AF_r4ol1dqJmP498Knrzu/view?usp=sharing)

how can i use role in projcect
------------------------------

[](#how-can-i-use-role-in-projcect)

- Databases Required for This Section ( role , role\_user )
- [![Watch the video]()](https://drive.google.com/file/d/16lktYEBw7-IkM3yVLaAMMlmdJKu8gLVF/view?usp=sharing)

Tips : In version 1.1.0, you can use this piece of code to check roles.
-----------------------------------------------------------------------

[](#tips--in-version-110-you-can-use-this-piece-of-code-to-check-roles)

```
  v1.1.0 =>

    ACL::isValidWithRoles(/* ROLES => like => "admin" , "user" , "operator" */);

  v1.0.0 =>
        $user = auth()->user();
        if (!$user->hasRoles(/* ROLES => like => "admin" , "user" , "operator" */)) {
            abort(403);
        }
```

#### Tips: You can also find a connection to roles and permisison in the permission\_role table . 👌

[](#tips-you-can-also-find-a-connection-to-roles-and-permisison-in-the-permission_role-table--)

\[For those who read to develop\]
=================================

[](#for-those-who-read-to-develop)

### Project Structure

[](#project-structure)

but how it worked ? 🤔

- This package has an interface that the run method should be implemented by the child's classes

```
interface IACL
{
    public static function run();
}
```

- This package contains a Trait in which there are methods for running the ACL

```
