PHPackages                             confrariaweb/laravel-entrust - 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. confrariaweb/laravel-entrust

ActivePackage

confrariaweb/laravel-entrust
============================

laravel access control package - ACL

010PHP

Since Aug 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/confrariaweb/laravel-entrust)[ Packagist](https://packagist.org/packages/confrariaweb/laravel-entrust)[ RSS](/packages/confrariaweb-laravel-entrust/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Package ACL Laravel
===================

[](#package-acl-laravel)

This is a simple, easy to use access control (ACL) package for laravel.

Package page:

Package installation
--------------------

[](#package-installation)

> Before starting, you need to make sure that the database access settings are configured.

In your terminal just use the command line below.

```
composer require confrariaweb/laravel-acl
```

After the installation is complete, add the following item to the array at app/http/kernel.php array $routeMiddleware.

```
'check.permission' => \ConfrariaWeb\Acl\Middleware\CheckPermission::class,
```

The next configuration step you should only use if you are not using the "confrariaweb / laravel-user" package, if you are using this package there is no need to implement the configuration below as it is already included in the "laravel-user" package.

```
class User extends Authenticatable
{
	//add this call to the application's user model
	use \ConfrariaWeb\Acl\Traits\AclTrait;
```

The next step is to place the configuration file in the "/config" directory.

```
php artisan vendor:publish --provider="ConfrariaWeb\Acl\Providers\AclServiceProvider"
```

We are almost there, the next commands are to restructure the configuration cache and run the migration of the tables respectively. At the command terminal, type the following commands.

```
php artisan config:cache
php artisan migrate
```

Optional: You can run the command below to create some items in the database, it is not mandatory and you can still modify them later if you find it convenient.

```
php artisan db:seed
```

Performing the above procedure the package is already available for use.

Package usage
-------------

[](#package-usage)

This package can be used at different points in your application.

### Use in middlewares

[](#use-in-middlewares)

To use the middleware, it uses the route name as a permission parameter. In the example below it checks if the user has the 'admin.profile' permission to access the route.

```
Route::get('admin/profile', function () {
    //
})->middleware('check.permission')->name('admin.profile');
```

### Use in controllers

[](#use-in-controllers)

The proper way to use access control on controllers is as follows.

#### By roles

[](#by-roles)

```
abort_unless(Auth::user()->hasRole('name-role'), 403);
```

#### By permissions

[](#by-permissions)

```
abort_unless(Auth::user()->hasPermission('name-permission'), 403);
```

#### Example of use

[](#example-of-use)

```
