PHPackages                             sanju/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. sanju/laravel-roles

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

sanju/laravel-roles
===================

Laravel roles and permissions

1.3(5mo ago)172MITPHPPHP ^7.4|| ^8.0 || ^8.4

Since Feb 25Pushed 5mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Roles And Permissions For Laravel 8.12
======================================

[](#roles-and-permissions-for-laravel-812)

A Powerful package for handling roles and permissions in Laravel 8.12 This package is an adaptation of [romanbican/roles](https://github.com/romanbican/roles) and [ultraware/roles](https://github.com/ultraware/roles/).

- [Installation](#installation)
    - [Composer](#composer)
    - [Service Provider](#service-provider)
    - [Config File And Migrations](#config-file-and-migrations)
    - [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)
- [Config File](#config-file)
- [More Information](#more-information)
- [License](#license)

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

[](#installation)

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

### Composer

[](#composer)

Pull this package in through Composer

```
composer require sanju/laravel-roles

```

### Service Provider

[](#service-provider)

Add the package to your application service providers in `config/app.php` file.

```
'providers' => [

    ...

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

],
```

### Config File

[](#config-file)

Publish the package config file and migrations to your application. Run these commands inside your terminal.

```
php artisan vendor:publish --provider="sanju\LaravelRoles\RolesServiceProvider" --tag=config
php artisan vendor:publish --provider="sanju\LaravelRoles\RolesServiceProvider" --tag=migrations
php artisan vendor:publish --provider="sanju\LaravelRoles\RolesServiceProvider" --tag=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 sanju\LararvelRoles\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:

```
