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

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

vildanbina/laravel-roles
========================

Powerful package for handling roles, permissions, and levels in Laravel. Supports Laravel 5.3 and higher

04BladeCI failing

Since Aug 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/vildanbina/laravel-roles)[ Packagist](https://packagist.org/packages/vildanbina/laravel-roles)[ RSS](/packages/vildanbina-laravel-roles/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#laravel-roles)

#### Table of contents

[](#table-of-contents)

- [About](#about)
- [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 Inheriting](#permissions-inheriting)
    - [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)

About
-----

[](#about)

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

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 vildanbina/laravel-roles

```

- 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...
     */
    vildanbina\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
```

### 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 vildanbina\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:

```
