AthenaeumAthenaeum
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
  • Version 6.x

    • Release Notes
    • Upgrade Guide
    • New to this...
    • Contribution Guide
    • Security Policy
    • Code of Conduct
    • Origin
  • ACL

    • Introduction
    • How to install
    • Setup
    • Permissions
    • Roles
    • Users
    • Cached Permissions
  • Audit

    • Audit
    • How to install
    • Setup
    • Recording
    • Events
  • Circuits

    • Circuits
    • How to install
    • Setup
    • Usage
    • Events
  • Collections

    • Collections
    • How to install
    • Summation

      • Summation Collection
      • Items Processor
  • Config

    • Configuration Loader
    • How to install
    • Setup
    • Load Configuration Files
    • Custom File Parsers
  • Console

    • Command and Schedule Registration
    • How to install
    • Setup
    • Commands
    • Schedules
  • Container

    • IoC Service Container
    • How to install
    • Container
    • List Resolver
  • Core

    • Athenaeum Core Application
    • How to install
    • Setup
    • Usage

      • Configuration
      • Service Providers
      • Service Container
      • Events
      • Caching
      • Logging
      • Console
      • Task Scheduling
      • Exception Handling
      • Extending Core Application
      • Testing
  • Database

    • Introduction
    • How to install
    • Models

      • Instantiatable
      • Sluggable
    • Query

      • Criteria (Query Filter)
  • Dto

    • Data Transfer Object (DTO)
    • How to install
    • Create Interface
    • Implement DTO
    • How to use
    • Populate
    • Export
    • Json
    • Serialization
    • Nested DTOs
    • Array DTO
  • ETags

    • ETags
    • How to install
    • Setup
    • Usage
    • Generators

      • Default Generator
      • Custom Generator
    • Eloquent Models
    • Macros
  • Events

    • Register Listeners and Subscribers
    • How to install
    • Setup
    • Listeners
    • Subscribers
  • Filters

    • Search Filter Utilities
    • Prerequisites
    • How to install
    • Setup
    • Processor
    • Filters Builder
    • Predefined Resources

      • Search Processor
      • Sorting Processor
      • Constraints Processor
      • Matching Processor
    • Tip: Create a base builder
  • Flysystem

    • Introduction
    • Database Adapter

      • Introduction
      • How to install
      • Setup
      • Data Deduplication
      • MIME-Type Detection
  • Http

    • Api

      • Http API
      • How to install
      • Setup
      • Resources

        • Introduction
        • Timestamps
        • Self-Link
        • Relations
        • Registrar
      • Middleware

        • Introduction
        • Request Must Be Json
        • Capture Fields To Select
    • Clients

      • Http Clients
      • How to install
      • Setup
      • Basic Usage
      • Available Methods

        • Fluent Api
        • Protocol Version
        • Base Uri
        • Http Method and Uri
        • Headers
        • Accept & Content-Type
        • Authentication
        • Http Query
        • Payload Format
        • Payload
        • Attachments
        • Cookies
        • Response Expectations
        • Middleware
        • Conditions
        • Criteria
        • Redirects
        • Timeout
        • Debugging
        • Logging
        • Driver Options
        • Driver
      • Http Query Builder

        • Introduction
        • Select
        • Where
        • Dates
        • Include
        • Pagination
        • Sorting
        • Raw Expressions
        • Custom Grammar
    • Cookies

      • Http Cookies
      • How to install
      • Usage
    • Messages

      • Http Messages
      • How to install
      • Serializers
  • Maintenance

    • Modes

      • Maintenance Modes
      • How to install
      • Setup
      • Basic Usage
      • Available Drivers
  • Mime Types

    • MIME-Types
    • How to install
    • Setup
    • Usage
    • Drivers

      • Available Drivers
      • File Info
  • Properties

    • Properties Overload
    • How to install
    • Usage
    • Naming Convention
    • Properties Visibility
  • Redmine

    • Redmine Api Client
    • How to install
    • Setup
    • General Usage

      • Supported Operations
      • Fetch list of resources
      • Find
      • Fetch
      • Create new record
      • Update existing record
      • Delete existing record
      • Relations
    • Available Resources

      • Predefined Resources
      • Attachments
      • Enumerations
      • Issue Relations
      • Users
      • User Groups
      • Roles
      • Project Memberships
      • Versions (Milestones)
      • Issue Categories
      • Trackers
  • Service

    • Service Registrar
    • How to install
    • How to use
  • Streams

    • Streams
    • How to install
    • Setup
    • How to use

      • Introduction
      • Open and Close
      • Raw Resource
      • Seeking
      • Reading
      • Writing
      • Size
      • Truncate
      • Flush
      • Hash
      • MIME-Type
      • Output
      • Locking
      • Transactions
      • Meta
      • Misc
  • Support

    • Introduction
    • How to install
    • Laravel Aware-of Helpers

      • How to use
      • Enforce Via Interface
      • Custom Default
      • Pros and Cons
      • Available Helpers
    • Aware-of Properties

      • Generator
      • Available Aware-of Helpers
    • Live Templates
  • Testing

    • Introduction
    • How to install
    • Test Cases
    • Testing Aware-of Helpers
  • Utils

    • Introduction
    • How to install
    • Array
    • Duration
    • Json
    • Math
    • Memory
    • Method Helper
    • Invoker
    • Populatable
    • String
    • Version
  • Validation

    • Introduction
    • How to install
    • Setup
    • Rules

      • Alpha-Dash-Dot
      • Semantic Version
You are viewing documentation for an outdated version. It is no longer supported!

Setup

In this section, setup of the ACL package is covered. It goes without saying, you should have some prior knowledge about how to work with Laravel's Authorization, before attempting to use this package's components.

  • Register Service Provider
  • Publish Assets (optional)
    • Publish Assets for Athenaeum Core Application
  • Configuration
    • Using your own models
  • The HasRoles trait
  • Migrate the database
  • Define permissions for Gate
    • When acl tables are missing...
  • Onward

Register Service Provider

Register AclServiceProvider inside your config/app.php.

return [

    // ... previous not shown ... //

    /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    */

    'providers' => [

        \Aedart\Acl\Providers\AclServiceProvider::class

        // ... remaining services not shown ... //
    ],
];

Publish Assets (optional)

Run vendor:publish to publish this package's configuration.

php artisan vendor:publish

After the command has completed, you should see config/acl.php in your application.

Publish Assets for Athenaeum Core Application

If you are using the Athenaeum Core Application, then run the following command to publish assets:

php {your-cli-app} vendor:publish-all

Configuration

Inside the config/acl.php file, you can change configuration for this package.

Using your own models

By default, this package's Eloquent models are used when interacting the various ACL components. To this this, simply state the class paths of your own models, in the models setting.

Note

If you choose to use your own models, then please make sure that they extend this package's Eloquent models - otherwise you will experience unexpected behavior.

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Models
    |--------------------------------------------------------------------------
    */

    'models' => [

        'user' => \App\Models\User::class,

        'role' => \App\Models\Acl\Role::class,

        'permission' => \App\Models\Acl\Permission::class,

        'group' => \App\Models\Acl\Permissions\Group::class
    ],

    // ... remaining not shown
];

The HasRoles trait

Your Eloquent User model must make use of the HasRoles trait. This will ensure that users can be assigned roles and thereby be granted permissions.

<?php

namespace App\Models;

use Aedart\Acl\Traits\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasRoles;
}

Migrate the database

Once you have configured the ACL components to your liking, you must migrate the database, so that the various tables can be installed.

php artisan migrate

Note

The current version of this package does not publish it's database migration files. They are loaded directly via AclServiceProvider, when the artisan migrate command is executed.

Define permissions for Gate

To ensure that Laravel's Authorisation Gate component is able to distinguish between which permission a user is granted or not, you must define these in your application's \App\Providers\AuthServiceProvider class. This can easily be accomplished via the ACL Registrar component's define() method.

<?php

namespace App\Providers;

use Aedart\Acl\Traits\RegistrarTrait;
use App\Models\User;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    use RegistrarTrait;

    // ... previous not shown ...

    public function boot(Gate $gate)
    {
        $this->registerPolicies();
        
        $this->getRegistrar()->define($gate);
    }
}

When acl tables are missing...

CI environment

If you have a CI environment, you might experience a "missing permissions table" failure, when installing a fresh instance of the application. This will happen when the AuthServiceProvider's boot() is invoked, before migrations are installed.

A possible solution for this, is to safely ignore the QueryException. E.g.:

use Aedart\Utils\Str;
use Illuminate\Database\QueryException;

try {
    $this->getRegistrar()->define($gate);
} catch(QueryException $e) {
    // Ignore exception - BUT ONLY IF it concerns missing permissions table!
    // Otherwise, re-throw the exception...
    if (!Str::contains($e->getMessage(), [
        'could not find driver (SQL: select * from `permissions`)',
        'relation "permissions" does not exist'
    ])) {
        throw $e;
    }
}

This issue can be very frustrating. Yet, this package dares not assume how to deal missing with migrations or boot order of your service providers.

Onward

You should now be ready to start working with the ACL components. In the upcoming sections, how to create permissions, roles, granting & revoking permissions ...etc, is covered in details.

Edit page
Last Updated: 16/02/2023, 09:10
Contributors: Alin Eugen Deac, alin
Prev
How to install
Next
Permissions