Skip to content
belemlc edited this page Oct 25, 2019 · 24 revisions

Installation

Composer

composer require kodeine/laravel-acl

If using Laravel 5.x make sure to install version 1.0

composer require kodeine/laravel-acl "^1.0"

Configuration

If you're using Laravel 5.4 or below, you need to register the service provider

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

'providers' => [
    ...
    Kodeine\Acl\AclServiceProvider::class,
],

Publish the package config to your application.

$ php artisan vendor:publish --provider="Kodeine\Acl\AclServiceProvider"

Run migrations.

$ php artisan migrate

Use your own models.

Once you publish, it publishes the configuration file, config/acl.php, where you can define your own models which should extend to Acl models.

return [
    'role'       => 'Kodeine\Acl\Models\Eloquent\Role',
    'permission' => 'Kodeine\Acl\Models\Eloquent\Permission',
];

Middleware Setup

Add the following to your app/Http/Kernel.php

protected $routeMiddleware = [
    ....
    'acl' => \Kodeine\Acl\Middleware\HasPermission::class,
];

Model Setup

Next, add the HasRole trait to your User model:

use Kodeine\Acl\Traits\HasRole;

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