PHPackages                             jeremykenedy/laravel-roles - 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. [Database &amp; ORM](/categories/database)
4. /
5. jeremykenedy/laravel-roles

ActivePackage[Database &amp; ORM](/categories/database)

jeremykenedy/laravel-roles
==========================

A Powerful package for handling roles and permissions in Laravel. Supports Laravel 5.3 up to 13.

v12.2.0(3mo ago)1.0k861.2k↓17.2%2037MITPHPPHP ^7.2|^8.0|^8.1|^8.2|^8.3CI passing

Since Feb 22Pushed 3mo ago37 watchersCompare

[ Source](https://github.com/jeremykenedy/laravel-roles)[ Packagist](https://packagist.org/packages/jeremykenedy/laravel-roles)[ GitHub Sponsors](https://github.com/jeremykenedy)[ Patreon](https://www.patreon.com/jeremykenedy)[ RSS](/packages/jeremykenedy-laravel-roles/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (14)Versions (64)Used By (7)

[![Laravel Roles](https://camo.githubusercontent.com/af058cacfcd8e1ca5ebda56a114125a28025a8a2eaa58c6959e023eee8ca8574/68747470733a2f2f6769746875622d70726f6a6563742d696d616765732e73332d75732d776573742d322e616d617a6f6e6177732e636f6d2f6c61726176656c2d626c6f636b65722f6c61726176656c2d726f6c65732d6c6f676f2e706e67)](https://camo.githubusercontent.com/af058cacfcd8e1ca5ebda56a114125a28025a8a2eaa58c6959e023eee8ca8574/68747470733a2f2f6769746875622d70726f6a6563742d696d616765732e73332d75732d776573742d322e616d617a6f6e6177732e636f6d2f6c61726176656c2d626c6f636b65722f6c61726176656c2d726f6c65732d6c6f676f2e706e67)

Laravel Roles
=============

[](#laravel-roles)

A Powerful package for handling roles and permissions in Laravel. Supports Laravel 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0, and 8.0+.

[![Total Downloads](https://camo.githubusercontent.com/1525da26bf2c51d0f0d6a566d7fa9914cf6a2c8f8e7e4a551faa0493c754fd59/68747470733a2f2f706f7365722e707567782e6f72672f6a6572656d796b656e6564792f6c61726176656c2d726f6c65732f642f746f74616c2e737667)](https://packagist.org/packages/jeremykenedy/laravel-roles)[![Latest Stable Version](https://camo.githubusercontent.com/94a8add8ed761e00b7cebc8e2508b4c727ee86bf35ac20f83c0f2d33b446a967/68747470733a2f2f706f7365722e707567782e6f72672f6a6572656d796b656e6564792f6c61726176656c2d726f6c65732f762f737461626c652e737667)](https://packagist.org/packages/jeremykenedy/laravel-roles)[![Scrutinizer-CI Build Status](https://camo.githubusercontent.com/a80db0740e80f859ade67ad3d2d02850ab6b70d73a1cf6f4b6b306cfa16dfaed/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6572656d796b656e6564792f6c61726176656c2d726f6c65732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jeremykenedy/laravel-roles/build-status/master)[![StyleCI](https://camo.githubusercontent.com/3b39f8b0c666e29c15ab1e12db41ed85a602c4022fc244f4b99be0efb550ab99/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f38323736383337392f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/82768379)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9015d156010370d1387270d6498dc8fbff9c52358052d36f1af8c26e663aaa4d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6572656d796b656e6564792f6c61726176656c2d726f6c65732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jeremykenedy/laravel-roles/?branch=master)[![Code Intelligence Status](https://camo.githubusercontent.com/593550393abc53f2bab385b71ce36dac5a514481965131487cbcd1a6ed0328c8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6572656d796b656e6564792f6c61726176656c2d726f6c65732f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![MadeWithLaravel.com shield](https://camo.githubusercontent.com/54bf43d3b4aec7c5b6b9c8e914381393937da6ab41c5bc84d3c17789282651b3/68747470733a2f2f6d616465776974686c61726176656c2e636f6d2f73746f726167652f7265706f2d736869656c64732f313336332d736869656c642e737667)](https://madewithlaravel.com/p/laravel-roles/shield-link)

- If you want to sponsor this, please consider sponsoring a contributor and NOT me. Thank you to all who contribute!!

#### Table of contents

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
    - [Composer](#composer)
    - [Service Provider](#service-provider)
    - [Publish All Assets](#publish-all-assets)
    - [Publish Specific Assets](#publish-specific-assets)
    - [HasRoleAndPermission Trait And Contract](#hasroleandpermission-trait-and-contract)
    - [Migrations and Seeds](#migrations-and-seeds)
    - [Migrate from Bican roles](#Migrate-from-bican-roles)
- [Usage](#usage)
    - [Creating Roles](#creating-roles)
    - [Attaching, Detaching and Syncing Roles](#attaching-detaching-and-syncing-roles)
    - [Assign a user role to new registered users](#assign-a-user-role-to-new-registered-users)
    - [Checking For Roles](#checking-for-roles)
    - [Levels](#levels)
    - [Creating Permissions](#creating-permissions)
    - [Attaching, Detaching and Syncing Permissions](#attaching-detaching-and-syncing-permissions)
    - [Checking For Permissions](#checking-for-permissions)
    - [Permissions Inheritance](#permissions-inheritance)
    - [Entity Check](#entity-check)
    - [Blade Extensions](#blade-extensions)
    - [Middleware](#middleware)
- [Configuration](#configuration)
    - [Environment File](#environment-file)
- [More Information](#more-information)
- [Optional GUI Routes](#optional-gui-routes)
- [Screen Shots](#screen-shots)
- [File Tree](#file-tree)
- [Opening an Issue](#opening-an-issue)
- [License](#license)

Features
--------

[](#features)

Laravel Roles FeaturesBuilt in migrations with ability to publish and modify your own.Built in seed with ability to publish and modify your own.Roles with levels and relationships to users, permissionsPermissions with relationships to users and levelsSoft deletes with full restore and destroyOptional CRUD of Roles and PermissionsLots of [configuration](#configuration) optionsAll Extendable from [.env](#environment-file)Installation
------------

[](#installation)

This package is very easy to set up. There are only couple of steps.

### Composer

[](#composer)

From your projects root folder in terminal run:

Laravel 5.8 and up use:

```
    composer require jeremykenedy/laravel-roles

```

Laravel 5.7 and below use:

```
    composer require jeremykenedy/laravel-roles:1.4.0

```

- Note: The major difference is that Laravel's users table migration out the box changed from `$table->increments('id');` to `$table->bigIncrements('id');` in Laravel 5.8.

### Service Provider

[](#service-provider)

- Laravel 5.5 and up Uses package auto discovery feature, no need to edit the `config/app.php` file.
- Laravel 5.4 and below Add the package to your application service providers in `config/app.php` file.

```
'providers' => [

    ...

    /**
     * Third Party Service Providers...
     */
    jeremykenedy\LaravelRoles\RolesServiceProvider::class,

],
```

### Publish All Assets

[](#publish-all-assets)

```
    php artisan vendor:publish --tag=laravelroles
```

### Publish Specific Assets

[](#publish-specific-assets)

```
    php artisan vendor:publish --tag=laravelroles-config
    php artisan vendor:publish --tag=laravelroles-migrations
    php artisan vendor:publish --tag=laravelroles-seeds
    php artisan vendor:publish --tag=laravelroles-views
    php artisan vendor:publish --tag=laravelroles-lang
```

### HasRoleAndPermission Trait And Contract

[](#hasroleandpermission-trait-and-contract)

1. Include `HasRoleAndPermission` trait and also implement `HasRoleAndPermission` contract inside your `User` model. See example below.
2. Include `use jeremykenedy\LaravelRoles\Traits\HasRoleAndPermission;` in the top of your `User` model below the namespace and implement the `HasRoleAndPermission` trait. See example below.

Example `User` model Trait And Contract:

```
