Download the PHP package macgriog/laravel-acl without Composer

On this page you can find all versions of the php package macgriog/laravel-acl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-acl

Build Status

ACL Package for Laravel

Simple access control based on User - Roles - Permissions, adapted from OctoberCMS.

How it works

Access is granted based on a User having a specific permission.

Roles are considered sets of permissions.

A User can have permissions.

A User can have multiple roles assigned.

For a single User, all permissions get merged.

Permissions are persisted in a JSON column, e.g.

{"backend.read" : 1, "backend.write" : -1, "system.shutdown": 0}

1 = permission grantend 0 = permission not granted -1 = forcibly revoke granted permission (e.g. if was inherited from Role)

Installation

To install via Composer, run the following command:

composer require macgriog/laravel-acl

For Laravel 5.4 and 5.3: add Service Provider

Note: Since Laravel 5.5 the ServiceProviders are being registered automatically.

If you are using an older version or have opted out of auto-discovery, add the following in config/app.php.

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

Database Migrations

This package works is meant to be used along a relational database like MariaDB. It expects 2 tables: users and roles. See the migration files for Schema details.

In a fresh Laravel install you can publish and run the necessary migrations via:

php artisan vendor:publish --provider="Macgriog\Acl\AclServiceProvider"
php artisan migrate

Please note, that this will require the doctrine/dbal package to be installed. It is not added as a composer dependency, because running the migrations is completely optional, depending on your use case.

Usage

User Model

Add the Trait to your User model and define the Role relation:

<?php

namespace App;

use Macgriog\Acl\Models\Role;
use Macgriog\Acl\Traits\UserPermissions;

class User extends Authenticatable
{
    use UserPermissions;

    /**
     * @return mixed
     */
    public function roles()
    {
        return $this->belongsToMany(
            Role::class,
            'role_user',
            'user_id',
            'role_id'
        );
    }

    public function getRoles()
    {
        if ($this->roles) {
            return $this->roles;
        }

        return $this->roles = $this->roles();
    }

}

Now you can check for permissions like so:

$user->hasAccess('update'); // true|false if User has Permission
$user->hasAccess(['update', 'create']) // true|false if ALL permissions are given
$user->hasAnyAccess(['update', 'create']) // true|false if ANY permission is given

Note: hasAccess and hasAnyAccess will check for a is_root attribute on the User. If a User is Root permissions are always considered as granted. You may adapt this behaviour to your needs using Eloquent's attribute accessors.

And you can set permissions:

$user->permissions = ['read' => true, 'update' => true];
$user->save();

Role Model

There is a sample Role class ready for usage. Roles - like Users - have a permissions column. This makes it easy to define sets of permissions and re-use them between Users by assigning Roles to them.

Route Middleware for Access Control

The package comes with a Middleware to be registered in your Route Middleware group:

Register in App\Http\Kernel.php:

protected $routeMiddleware = [
    // ...
    'acl' => \Dreipc\Acl\Middleware\CheckPermission::class,
];

Example usage:

Route::get('backend')->middleware('acl:backend.access');

It takes the required permissions as arguments and aborts if not ALL of them are granted to the current User.

Tests

Run tests via PHPUnit:

vendor/bin/phpunit

References


All versions of laravel-acl with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
laravel/framework Version ^5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package macgriog/laravel-acl contains the following files

Loading the files please wait ....