All Projects → BeatSwitch → Lock Laravel

BeatSwitch / Lock Laravel

Licence: mit
This package is a Laravel 5 driver for Lock

Projects that are alternatives of or similar to Lock Laravel

Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+1616.15%)
Mutual labels:  laravel, permissions, acl
Brandenburg
Laravel Authentication Package
Stars: ✭ 79 (-50.93%)
Mutual labels:  laravel, permissions, acl
Laratrust
Handle roles and permissions in your Laravel application
Stars: ✭ 1,799 (+1017.39%)
Mutual labels:  laravel, permissions, acl
Laravel Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Stars: ✭ 136 (-15.53%)
Mutual labels:  laravel, permissions, acl
Vakt
Attribute-based access control (ABAC) SDK for Python
Stars: ✭ 92 (-42.86%)
Mutual labels:  permissions, acl
Laravel Vue Starter
Well Documented Laravel Starter App From Development to Production. For Full Blown RESTFUL API and SPA with Beautiful UI Using Buefy / ElementUi For Reusable Vue Components
Stars: ✭ 76 (-52.8%)
Mutual labels:  laravel, acl
Roles
Powerful package for handling roles in Laravel
Stars: ✭ 102 (-36.65%)
Mutual labels:  laravel, acl
Accesscontrol
Role and Attribute based Access Control for Node.js
Stars: ✭ 1,723 (+970.19%)
Mutual labels:  permissions, acl
Ngx Permissions
Permission and roles based access control for your angular(angular 2,4,5,6,7,9+) applications(AOT, lazy modules compatible
Stars: ✭ 749 (+365.22%)
Mutual labels:  permissions, acl
Simpleacl
Simple ACL for PHP
Stars: ✭ 105 (-34.78%)
Mutual labels:  permissions, acl
Guardian
Eloquent Guardian is a simple permissions system for your users. While there are many other packages for permissions, this one solves everything in the most eloquent way.
Stars: ✭ 121 (-24.84%)
Mutual labels:  laravel, permissions
Laravel Nova Permission
A Laravel Nova tool for the Spatie Permission package
Stars: ✭ 59 (-63.35%)
Mutual labels:  laravel, permissions
Laravel Auth
A powerful authentication, authorization and verification package built on top of Laravel. It provides developers with Role Based Access Control, Two-Factor Authentication, Social Authentication, and much more, compatible Laravel’s standard API and fully featured out of the box.
Stars: ✭ 128 (-20.5%)
Mutual labels:  laravel, permissions
Laravel Governor
Manage authorization with granular role-based permissions in your Laravel Apps.
Stars: ✭ 131 (-18.63%)
Mutual labels:  laravel, permissions
Sentinel
A framework agnostic authentication & authorization system.
Stars: ✭ 1,354 (+740.99%)
Mutual labels:  laravel, permissions
Lock
A flexible, driver based Acl package for PHP 5.4+
Stars: ✭ 913 (+467.08%)
Mutual labels:  permissions, acl
Unix Permissions
Swiss Army knife for Unix permissions
Stars: ✭ 106 (-34.16%)
Mutual labels:  permissions, acl
Defender
Roles & Permissions for Laravel 8 / 7 / 6 / 5
Stars: ✭ 403 (+150.31%)
Mutual labels:  laravel, acl
Laravel Acl
This package helps you to associate users with permissions and permission groups with laravel framework
Stars: ✭ 404 (+150.93%)
Mutual labels:  laravel, acl
Roles Permissions Laravel
Roles and Permissions implementation on Laravel 5.4
Stars: ✭ 121 (-24.84%)
Mutual labels:  laravel, acl

Lock - Laravel 5 Driver

Build Status Code Climate Test Coverage Software License Packagist Version Total Downloads

I'm sad to say that Lock is currently not maintained. I won't be able to offer support or accept new contributions for the current time being. Other priorities are keeping me from putting the work into Lock that it deserves. Eventually I'll try to pick up work again but unfortunately I cannot say when. My thanks goes out to all the contributors and users.

-- Dries

This package is a Laravel 5 driver for Lock. Check the documentation of Lock for more info. It requires at least PHP 5.6.

Table of Contents

Installation

Install this package through Composer.

$ composer require beatswitch/lock-laravel

Register the service provider in your app.php config file.

BeatSwitch\Lock\Integrations\Laravel\LockServiceProvider::class,

Register the facades in your app.php config file.

'Lock' => BeatSwitch\Lock\Integrations\Laravel\Facades\Lock::class,
'LockManager' => BeatSwitch\Lock\Integrations\Laravel\Facades\LockManager::class,

Publish the configuration file. After publishing you can edit the configuration options at config/lock.php.

$ php artisan vendor:publish --provider="BeatSwitch\Lock\Integrations\Laravel\LockServiceProvider" --tag="config"

If you're using the database driver you should run the package's migrations. This will create the database table where all permissions will be stored.

$ php artisan vendor:publish --provider="BeatSwitch\Lock\Integrations\Laravel\LockServiceProvider" --tag="migrations"
$ php artisan migrate

Please read the main Lock documentation for setting up the caller contract on your User model and for more in-depth documentation on how Lock works.

Also make sure to set the BeatSwitch\Lock\LockAware trait on your User model. That way your authenticated user will receive a Lock instance of itself so you can call permissions directly from your user object. If no user is authenticated, a SimpleCaller object will be bootstrapped which has the guest role. That way you can still use the Lock facade. If you want the LockAware trait to work on the User model you'll need to activate it with a middleware. Register the middleware below after the StartSession middleware.

\BeatSwitch\Lock\Integrations\Laravel\Middleware\InitLockAwareTrait::class,

Usage

Setting roles and aliases

You can register roles and aliases beforehand through the permissions callback in the config file. Here you can say which actions should be grouped under an alias or set which roles should inherit permissions from each other.

<?php

use BeatSwitch\Lock\Manager;

return [

    ...

    'permissions' => function (Manager $manager) {
        // Set your configuration here.
        $manager->alias('manage', ['create', 'read', 'update', 'delete']);
        $manager->setRole('user', 'guest');
        $manager->setRole(['editor', 'admin'], 'user');
    },
];

Setting permissions with the array driver

If you're using the array driver you can set all your permissions beforehand in the same permissions callback from above.

<?php

use BeatSwitch\Lock\Callers\SimpleCaller;
use BeatSwitch\Lock\Drivers\ArrayDriver;
use BeatSwitch\Lock\Manager;

return [

    ...

    'permissions' => function (Manager $manager) {
        // Only set permissions beforehand when using the array driver.
        if ($manager->getDriver() instanceof ArrayDriver) {
            // Set some role permissions.
            $manager->role('guest')->allow('read', 'posts');
            $manager->role('user')->allow('create', 'posts');
            $manager->role('editor')->allow('publish', 'posts');

            // Set permissions for a specific user.
            $manager->caller(new SimpleCaller('users', 1))->allow('publish', 'posts');
        }
    },
];

Using the database driver

Enable the database driver by switching the driver type in the config file. The database driver will use your default database connection to store permissions to your database. You can choose which table to store the permissions into by changing the setting in the config file.

Now that you have your database driver set up, you're ready to create a UI for your permissions and use the lock manager instance in your application to change permissions for callers or roles.

Using the facades

This package ships with two facades: the Lock facade which holds the BeatSwitch\Lock\Lock instance for your current authenticated user (or the guest user if no user is authenticated) and the LockManager class which can be used to bootstrap new lock instances for callers or roles.

Checking permissions for the current user is easy.

Lock::can('create', 'posts');
Lock::cannot('publish', $post);

// Or use the auth instance. This is possible because your User model has the LockAware trait.
Auth::user()->can('create', 'posts');

Use the manager to set permissions.

LockManager::caller($user)->allow('create', 'posts');
LockManager::caller($user)->allow('all');
LockManager::role('editor')->allow('create', 'posts');

Using dependency injection

You can use Laravel's IoC container to insert an instance of the current user's lock instance or the lock manager instance into your classes or controllers.

<?php

use BeatSwitch\Lock\Manager;

class UserManagementController extends BaseController
{
    protected $lockManager;

    public function __construct(Manager $lockManager)
    {
        $this->lockManager = $lockManager;
    }

    public function togglePermission()
    {
        $userId = Input::get('user');
        $action = Input::get('action');
        $resource = Input::get('resource');

        $user = User::find($userId);

        $this->lockManager->caller($user)->toggle($action, $resource);

        return Redirect::route('user_management');
    }
}

Maintainer

Lock is currently unmaintained.

This package is currently maintained by Dries Vints.
If you have any questions please don't hesitate to ask them in an issue.

Contributing

Please see the contributing file for details.

Changelog

You can see a list of changes for each release in the changelog file.

License

The MIT License. Please see the license file for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].