PHPackages                             beatswitch/lock-laravel - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. beatswitch/lock-laravel

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

beatswitch/lock-laravel
=======================

A Laravel Driver for Lock.

0.5.2(8y ago)15529.1k↓33.3%21[3 issues](https://github.com/BeatSwitch/lock-laravel/issues)1MITPHPPHP &gt;=5.6

Since Dec 8Pushed 8y ago16 watchersCompare

[ Source](https://github.com/BeatSwitch/lock-laravel)[ Packagist](https://packagist.org/packages/beatswitch/lock-laravel)[ Docs](https://github.com/BeatSwitch/lock)[ RSS](/packages/beatswitch-lock-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (16)Used By (1)

Lock - Laravel 5 Driver
=======================

[](#lock---laravel-5-driver)

[![Build Status](https://camo.githubusercontent.com/be3434dd1fe78c098d78682592f62b5a93633130df2b5d099ccbf932c616776b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f426561745377697463682f6c6f636b2d6c61726176656c2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/BeatSwitch/lock-laravel)[![Code Climate](https://camo.githubusercontent.com/216a2c4063b5f7b5f0e0daab93067f775ec2051217470555bd197f4705974ebf/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f426561745377697463682f6c6f636b2d6c61726176656c2f6261646765732f6770612e737667)](https://codeclimate.com/github/BeatSwitch/lock-laravel)[![Test Coverage](https://camo.githubusercontent.com/5ab895ccdd5fbdfb46270c39d6e8e05b321b6e50d98bb15bde9d16dba175d204/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f426561745377697463682f6c6f636b2d6c61726176656c2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/BeatSwitch/lock-laravel/coverage)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Packagist Version](https://camo.githubusercontent.com/32a0661de75a17baecf72805e2873686e2412c6960ce0f95d4e94413e3fd9d89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626561747377697463682f6c6f636b2d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beatswitch/lock-laravel)[![Total Downloads](https://camo.githubusercontent.com/98b8f6aea54e139372882e9966697abc444d34bed02a2dbaee5e4270c1b6d086/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626561747377697463682f6c6f636b2d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beatswitch/lock-laravel)

> 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](https://github.com/BeatSwitch/lock). Check the documentation of Lock for more info. It requires at least PHP 5.6.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Setting roles and aliases](#setting-roles-and-aliases)
    - [Setting permissions with the array driver](#setting-permissions-with-the-array-driver)
    - [Using the database driver](#using-the-database-driver)
    - [Using the facades](#using-the-facades)
    - [Using dependency injection](#using-dependency-injection)
- [Maintainer](#maintainer)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

Installation
------------

[](#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](https://github.com/BeatSwitch/lock) 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
-----

[](#usage)

### Setting roles and aliases

[](#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.

```
