A Powerful package for handling roles and permissions in Laravel with GUI.

Overview

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 Latest Stable Version Travis-CI Build Status Scrutinizer-CI Build Status StyleCI Scrutinizer Code Quality Code Intelligence Status License: MIT MadeWithLaravel.com shield

Table of contents

Features

Laravel Roles Features
Built 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, permissions
Permissions with relationships to users and levels
Soft deletes with full restore and destroy
Optional CRUD of Roles and Permissions
Lots of configuration options
All Extendable from .env

Installation

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

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

  • 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

    php artisan vendor:publish --tag=laravelroles

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

  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:



namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use jeremykenedy\LaravelRoles\Traits\HasRoleAndPermission;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    use HasRoleAndPermission;

    // rest of your model ...
}

Migrations and seeds

This uses the default users table which is in Laravel. You should already have the migration file for the users table available and migrated.

  1. Setup the needed tables:

    php artisan migrate

  2. Update database\seeds\DatabaseSeeder.php to include the seeds. See example below.



use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Database\Seeders\PermissionsTableSeeder;
use Database\Seeders\RolesTableSeeder;
use Database\Seeders\ConnectRelationshipsSeeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

            $this->call(PermissionsTableSeeder::class);
            $this->call(RolesTableSeeder::class);
            $this->call(ConnectRelationshipsSeeder::class);
            //$this->call('UsersTableSeeder');

        Model::reguard();
    }
}
  1. Seed an initial set of Permissions, Roles, and Users with roles.
composer dump-autoload
php artisan db:seed

Roles Seeded

Property Value
Name Admin
Slug admin
Description Admin Role
Level 5
Property Value
Name User
Slug user
Description User Role
Level 1
Property Value
Name Unverified
Slug unverified
Description Unverified Role
Level 0

Permissions Seeded:

Property Value
name Can View Users
slug view.users
description Can view users
model Permission
Property Value
name Can Create Users
slug create.users
description Can create new users
model Permission
Property Value
name Can Edit Users
slug edit.users
description Can edit users
model Permission
Property Value
name Can Delete Users
slug delete.users
description Can delete users
model Permission

And that's it!


Migrate from bican roles

If you migrate from bican/roles to jeremykenedy/LaravelRoles you will need to update a few things.

  • Change all calls to can, canOne and canAll to hasPermission, hasOnePermission, hasAllPermissions.
  • Change all calls to is, isOne and isAll to hasRole, hasOneRole, hasAllRoles.

Usage

Creating Roles

$adminRole = config('roles.models.role')::create([
    'name' => 'Admin',
    'slug' => 'admin',
    'description' => '',
    'level' => 5,
]);

$moderatorRole = config('roles.models.role')::create([
    'name' => 'Forum Moderator',
    'slug' => 'forum.moderator',
]);

Because of Slugable trait, if you make a mistake and for example leave a space in slug parameter, it'll be replaced with a dot automatically, because of str_slug function.

Attaching, Detaching and Syncing Roles

It's really simple. You fetch a user from database and call attachRole method. There is BelongsToMany relationship between User and Role model.

$user = config('roles.models.defaultUser')::find($id);

$user->attachRole($adminRole); // you can pass whole object, or just an id
$user->detachRole($adminRole); // in case you want to detach role
$user->detachAllRoles(); // in case you want to detach all roles
$user->syncRoles($roles); // you can pass Eloquent collection, or just an array of ids

Assign a user role to new registered users

You can assign the user a role upon the users registration by updating the file app\Http\Controllers\Auth\RegisterController.php. You can assign a role to a user upon registration by including the needed models and modifying the create() method to attach a user role. See example below:

  • Updated create() method of app\Http\Controllers\Auth\RegisterController.php:
    protected function create(array $data)
    {
        $user = config('roles.models.defaultUser')::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);

        $role = config('roles.models.role')::where('name', '=', 'User')->first();  //choose the default role upon user creation.
        $user->attachRole($role);

        return $user;

    }

Checking For Roles

You can now check if the user has required role.

if ($user->hasRole('admin')) { // you can pass an id or slug
    //
}

You can also do this:

if ($user->isAdmin()) {
    //
}

And of course, there is a way to check for multiple roles:

if ($user->hasRole(['admin', 'moderator'])) {
    /*
    | Or alternatively:
    | $user->hasRole('admin, moderator'), $user->hasRole('admin|moderator'),
    | $user->hasOneRole('admin, moderator'), $user->hasOneRole(['admin', 'moderator']), $user->hasOneRole('admin|moderator')
    */

    // The user has at least one of the roles
}

if ($user->hasRole(['admin', 'moderator'], true)) {
    /*
    | Or alternatively:
    | $user->hasRole('admin, moderator', true), $user->hasRole('admin|moderator', true),
    | $user->hasAllRoles('admin, moderator'), $user->hasAllRoles(['admin', 'moderator']), $user->hasAllRoles('admin|moderator')
    */

    // The user has all roles
}

Levels

When you are creating roles, there is optional parameter level. It is set to 1 by default, but you can overwrite it and then you can do something like this:

if ($user->level() > 4) {
    //
}

If user has multiple roles, method level returns the highest one.

Level has also big effect on inheriting permissions. About it later.

Creating Permissions

It's very simple thanks to Permission model called from config('roles.models.permission').

$createUsersPermission = config('roles.models.permission')::create([
    'name' => 'Create users',
    'slug' => 'create.users',
    'description' => '', // optional
]);

$deleteUsersPermission = config('roles.models.permission')::create([
    'name' => 'Delete users',
    'slug' => 'delete.users',
]);

Attaching, Detaching and Syncing Permissions

You can attach permissions to a role or directly to a specific user (and of course detach them as well).

$role = config('roles.models.role')::find($roleId);
$role->attachPermission($createUsersPermission); // permission attached to a role

$user = config('roles.models.defaultUser')::find($userId);
$user->attachPermission($deleteUsersPermission); // permission attached to a user
$role->detachPermission($createUsersPermission); // in case you want to detach permission
$role->detachAllPermissions(); // in case you want to detach all permissions
$role->syncPermissions($permissions); // you can pass Eloquent collection, or just an array of ids

$user->detachPermission($deleteUsersPermission);
$user->detachAllPermissions();
$user->syncPermissions($permissions); // you can pass Eloquent collection, or just an array of ids

Checking For Permissions

if ($user->hasPermission('create.users')) { // you can pass an id or slug
    //
}

if ($user->canDeleteUsers()) {
    //
}

You can check for multiple permissions the same way as roles. You can make use of additional methods like hasOnePermission or hasAllPermissions.

Permissions Inheritance

By default, roles with higher level inherit all permissions from roles with lower level.

For example:

You have three roles: user, moderator and admin. User has a permission to read articles, moderator can manage comments and admin can create articles. User has a level 1, moderator level 2 and admin level 3. With inheritance enabled, moderator and administrator also have the permission to read articles, and administrator can manage comments as well.

If you don't want the permissions inheritance feature enabled in you application, set the config value roles.inheritance (or its corresponding .env parameter, ROLES_INHERITANCE) to false. Alternatively, simply ignore the level parameter when you're creating roles.

Entity Check

Let's say you have an article and you want to edit it. This article belongs to a user (there is a column user_id in articles table).

use App\Article;

$editArticlesPermission = config('roles.models.permission')::create([
    'name' => 'Edit articles',
    'slug' => 'edit.articles',
    'model' => 'App\Article',
]);

$user->attachPermission($editArticlesPermission);

$article = Article::find(1);

if ($user->allowed('edit.articles', $article)) { // $user->allowedEditArticles($article)
    //
}

This condition checks if the current user is the owner of article. If not, it will be looking inside user permissions for a row we created before.

if ($user->allowed('edit.articles', $article, false)) { // now owner check is disabled
    //
}

Blade Extensions

There are four Blade extensions. Basically, it is replacement for classic if statements.

@role('admin') // @if(Auth::check() && Auth::user()->hasRole('admin'))
    // user has admin role
@endrole

@permission('edit.articles') // @if(Auth::check() && Auth::user()->hasPermission('edit.articles'))
    // user has edit articles permissison
@endpermission

@level(2) // @if(Auth::check() && Auth::user()->level() >= 2)
    // user has level 2 or higher
@endlevel

@allowed('edit', $article) // @if(Auth::check() && Auth::user()->allowed('edit', $article))
    // show edit button
@endallowed

@role('admin|moderator', true) // @if(Auth::check() && Auth::user()->hasRole('admin|moderator', true))
    // user has admin and moderator role
@else
    // something else
@endrole

Middleware

This package comes with VerifyRole, VerifyPermission and VerifyLevel middleware. The middleware aliases are already registered in \jeremykenedy\LaravelRoles\RolesServiceProvider as of 1.7. You can optionally add them inside your app/Http/Kernel.php file with your own aliases like outlined below:

/**
 * The application's route middleware.
 *
 * @var array
 */
protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
    'role' => \jeremykenedy\LaravelRoles\App\Http\Middleware\VerifyRole::class,
    'permission' => \jeremykenedy\LaravelRoles\App\Http\Middleware\VerifyPermission::class,
    'level' => \jeremykenedy\LaravelRoles\App\Http\Middleware\VerifyLevel::class,
];

Now you can easily protect your routes.

Route::get('/', function () {
    //
})->middleware('role:admin');

Route::get('/', function () {
    //
})->middleware('permission:edit.articles');

Route::get('/', function () {
    //
})->middleware('level:2'); // level >= 2

Route::get('/', function () {
    //
})->middleware('role:admin', 'level:2'); // level >= 2 and Admin

Route::group(['middleware' => ['role:admin']], function () {
    //
});

It throws \jeremykenedy\LaravelRoles\App\Exceptions\RoleDeniedException, \jeremykenedy\LaravelRoles\App\Exceptions\PermissionDeniedException or \jeremykenedy\LaravelRoles\App\Exceptions\LevelDeniedException exceptions if it goes wrong.

You can catch these exceptions inside app/Exceptions/Handler.php file and do whatever you want.

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {

        $userLevelCheck = $exception instanceof \jeremykenedy\LaravelRoles\App\Exceptions\RoleDeniedException ||
            $exception instanceof \jeremykenedy\LaravelRoles\App\Exceptions\PermissionDeniedException ||
            $exception instanceof \jeremykenedy\LaravelRoles\App\Exceptions\LevelDeniedException;

        if ($userLevelCheck) {

            if ($request->expectsJson()) {
                return Response::json(array(
                    'error'    =>  403,
                    'message'   =>  'Unauthorized.'
                ), 403);
            }

            abort(403);
        }

        return parent::render($request, $exception);
    }

Configuration

  • You can change connection for models, slug separator, models path and there is also a handy pretend feature.
  • There are many configurable options which have been extended to be able to configured via .env file variables.
  • Editing the configuration file directly may not needed becuase of this.
  • See config file: roles.php.
[ 'enabled' => false, 'options' => [ 'hasRole' => true, 'hasPermission' => true, 'allowed' => true, ], ], /* |-------------------------------------------------------------------------- | Default Migrations |-------------------------------------------------------------------------- | | These are the default package migrations. If you publish the migrations | to your project, then this is not necessary and should be disabled. This | will enable our default migrations. | */ 'defaultMigrations' => [ 'enabled' => env('ROLES_MIGRATION_DEFAULT_ENABLED', false), ], /* |-------------------------------------------------------------------------- | Default Seeds |-------------------------------------------------------------------------- | | These are the default package seeds. You can seed the package built | in seeds without having to seed them. These seed directly from | the package. These are not the published seeds. | */ 'defaultSeeds' => [ 'PermissionsTableSeeder' => env('ROLES_SEED_DEFAULT_PERMISSIONS', true), 'RolesTableSeeder' => env('ROLES_SEED_DEFAULT_ROLES', true), 'ConnectRelationshipsSeeder' => env('ROLES_SEED_DEFAULT_RELATIONSHIPS', true), 'UsersTableSeeder' => env('ROLES_SEED_DEFAULT_USERS', false), ], /* |-------------------------------------------------------------------------- | Laravel Roles GUI Settings |-------------------------------------------------------------------------- | | This is the GUI for Laravel Roles to be able to CRUD them | easily and fast. This is optional and is not needed | for your application. | */ // Enable Optional Roles Gui 'rolesGuiEnabled' => env('ROLES_GUI_ENABLED', false), // Enable `auth` middleware 'rolesGuiAuthEnabled' => env('ROLES_GUI_AUTH_ENABLED', true), // Enable Roles GUI middleware 'rolesGuiMiddlewareEnabled' => env('ROLES_GUI_MIDDLEWARE_ENABLED', true), // Optional Roles GUI Middleware 'rolesGuiMiddleware' => env('ROLES_GUI_MIDDLEWARE', 'role:admin'), // User Permissions or Role needed to create a new role 'rolesGuiCreateNewRolesMiddlewareType' => env('ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE', 'role'), //permissions or roles 'rolesGuiCreateNewRolesMiddleware' => env('ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX // User Permissions or Role needed to create a new permission 'rolesGuiCreateNewPermissionMiddlewareType' => env('ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'role'), //permissions or roles 'rolesGuiCreateNewPermissionsMiddleware' => env('ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX // The parent blade file 'bladeExtended' => env('ROLES_GUI_BLADE_EXTENDED', 'layouts.app'), // Blade Extension Placement 'bladePlacement' => env('ROLES_GUI_BLADE_PLACEMENT', 'yield'), 'bladePlacementCss' => env('ROLES_GUI_BLADE_PLACEMENT_CSS', 'inline_template_linked_css'), 'bladePlacementJs' => env('ROLES_GUI_BLADE_PLACEMENT_JS', 'inline_footer_scripts'), // Titles placement extend 'titleExtended' => env('ROLES_GUI_TITLE_EXTENDED', 'template_title'), // Switch Between bootstrap 3 `panel` and bootstrap 4 `card` classes 'bootstapVersion' => env('ROLES_GUI_BOOTSTRAP_VERSION', '4'), // Additional Card classes for styling - // See: https://getbootstrap.com/docs/4.0/components/card/#background-and-color // Example classes: 'text-white bg-primary mb-3' 'bootstrapCardClasses' => env('ROLES_GUI_CARD_CLASSES', ''), // Bootstrap Tooltips 'tooltipsEnabled' => env('ROLES_GUI_TOOLTIPS_ENABLED', true), // jQuery 'enablejQueryCDN' => env('ROLES_GUI_JQUERY_CDN_ENABLED', true), 'JQueryCDN' => env('ROLES_GUI_JQUERY_CDN_URL', 'https://code.jquery.com/jquery-3.3.1.min.js'), // Selectize JS 'enableSelectizeJsCDN' => env('ROLES_GUI_SELECTIZEJS_CDN_ENABLED', true), 'SelectizeJsCDN' => env('ROLES_GUI_SELECTIZEJS_CDN_URL', 'https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/js/standalone/selectize.min.js'), 'enableSelectizeJs' => env('ROLES_GUI_SELECTIZEJS_ENABLED', true), 'enableSelectizeJsCssCDN' => env('ROLES_GUI_SELECTIZEJS_CSS_CDN_ENABLED', true), 'SelectizeJsCssCDN' => env('ROLES_GUI_SELECTIZEJS_CSS_CDN_URL', 'https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/css/selectize.min.css'), // Font Awesome 'enableFontAwesomeCDN' => env('ROLES_GUI_FONT_AWESOME_CDN_ENABLED', true), 'fontAwesomeCDN' => env('ROLES_GUI_FONT_AWESOME_CDN_URL', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'), // Flash Messaging 'builtInFlashMessagesEnabled' => env('ROLES_GUI_FLASH_MESSAGES_ENABLED', true), /* |-------------------------------------------------------------------------- | Laravel Roles API Settings |-------------------------------------------------------------------------- | | This is the API for Laravel Roles to be able to CRUD them | easily and fast via an API. This is optional and is | not needed for your application. | */ 'rolesApiEnabled' => env('ROLES_API_ENABLED', false), // Enable `auth` middleware 'rolesAPIAuthEnabled' => env('ROLES_API_AUTH_ENABLED', true), // Enable Roles API middleware 'rolesAPIMiddlewareEnabled' => env('ROLES_API_MIDDLEWARE_ENABLED', true), // Optional Roles API Middleware 'rolesAPIMiddleware' => env('ROLES_API_MIDDLEWARE', 'role:admin'), // User Permissions or Role needed to create a new role 'rolesAPICreateNewRolesMiddlewareType' => env('ROLES_API_CREATE_ROLE_MIDDLEWARE_TYPE', 'role'), //permissions or roles 'rolesAPICreateNewRolesMiddleware' => env('ROLES_API_CREATE_ROLE_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX // User Permissions or Role needed to create a new permission 'rolesAPICreateNewPermissionMiddlewareType' => env('ROLES_API_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'role'), //permissions or roles 'rolesAPICreateNewPermissionsMiddleware' => env('ROLES_API_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX /* |-------------------------------------------------------------------------- | Laravel Roles GUI Datatables Settings |-------------------------------------------------------------------------- */ 'enabledDatatablesJs' => env('ROLES_GUI_DATATABLES_JS_ENABLED', false), 'datatablesJsStartCount' => env('ROLES_GUI_DATATABLES_JS_START_COUNT', 25), 'datatablesCssCDN' => env('ROLES_GUI_DATATABLES_CSS_CDN', 'https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css'), 'datatablesJsCDN' => env('ROLES_GUI_DATATABLES_JS_CDN', 'https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js'), 'datatablesJsPresetCDN' => env('ROLES_GUI_DATATABLES_JS_PRESET_CDN', 'https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js'), /* |-------------------------------------------------------------------------- | Laravel Roles Package Integration Settings |-------------------------------------------------------------------------- */ 'laravelUsersEnabled' => env('ROLES_GUI_LARAVEL_ROLES_ENABLED', false), ]; ">


return [

    /*
    |--------------------------------------------------------------------------
    | Package Connection
    |--------------------------------------------------------------------------
    |
    | You can set a different database connection for this package. It will set
    | new connection for models Role and Permission. When this option is null,
    | it will connect to the main database, which is set up in database.php
    |
    */

    'connection'            => env('ROLES_DATABASE_CONNECTION', null),
    'rolesTable'            => env('ROLES_ROLES_DATABASE_TABLE', 'roles'),
    'roleUserTable'         => env('ROLES_ROLE_USER_DATABASE_TABLE', 'role_user'),
    'permissionsTable'      => env('ROLES_PERMISSIONS_DATABASE_TABLE', 'permissions'),
    'permissionsRoleTable'  => env('ROLES_PERMISSION_ROLE_DATABASE_TABLE', 'permission_role'),
    'permissionsUserTable'  => env('ROLES_PERMISSION_USER_DATABASE_TABLE', 'permission_user'),

    /*
    |--------------------------------------------------------------------------
    | Slug Separator
    |--------------------------------------------------------------------------
    |
    | Here you can change the slug separator. This is very important in matter
    | of magic method __call() and also a `Slugable` trait. The default value
    | is a dot.
    |
    */

    'separator' => env('ROLES_DEFAULT_SEPARATOR', '.'),

    /*
    |--------------------------------------------------------------------------
    | Models
    |--------------------------------------------------------------------------
    |
    | If you want, you can replace default models from this package by models
    | you created. Have a look at `jeremykenedy\LaravelRoles\Models\Role` model and
    | `jeremykenedy\LaravelRoles\Models\Permission` model.
    |
    */

    'models' => [
        'role'          => env('ROLES_DEFAULT_ROLE_MODEL', jeremykenedy\LaravelRoles\Models\Role::class),
        'permission'    => env('ROLES_DEFAULT_PERMISSION_MODEL', jeremykenedy\LaravelRoles\Models\Permission::class),
        'defaultUser'   => env('ROLES_DEFAULT_USER_MODEL', config('auth.providers.users.model')),
    ],

    /*
    |--------------------------------------------------------------------------
    | Roles, Permissions and Allowed "Pretend"
    |--------------------------------------------------------------------------
    |
    | You can pretend or simulate package behavior no matter what is in your
    | database. It is really useful when you are testing you application.
    | Set up what will methods hasRole(), hasPermission() and allowed() return.
    |
    */

    'pretend' => [
        'enabled' => false,
        'options' => [
            'hasRole'       => true,
            'hasPermission' => true,
            'allowed'       => true,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Default Migrations
    |--------------------------------------------------------------------------
    |
    | These are the default package migrations. If you publish the migrations
    | to your project, then this is not necessary and should be disabled. This
    | will enable our default migrations.
    |
    */
    'defaultMigrations' => [
        'enabled'        => env('ROLES_MIGRATION_DEFAULT_ENABLED', false),
    ],

    /*
    |--------------------------------------------------------------------------
    | Default Seeds
    |--------------------------------------------------------------------------
    |
    | These are the default package seeds. You can seed the package built
    | in seeds without having to seed them. These seed directly from
    | the package. These are not the published seeds.
    |
    */

    'defaultSeeds' => [
        'PermissionsTableSeeder'        => env('ROLES_SEED_DEFAULT_PERMISSIONS', true),
        'RolesTableSeeder'              => env('ROLES_SEED_DEFAULT_ROLES', true),
        'ConnectRelationshipsSeeder'    => env('ROLES_SEED_DEFAULT_RELATIONSHIPS', true),
        'UsersTableSeeder'              => env('ROLES_SEED_DEFAULT_USERS', false),
    ],

    /*
    |--------------------------------------------------------------------------
    | Laravel Roles GUI Settings
    |--------------------------------------------------------------------------
    |
    | This is the GUI for Laravel Roles to be able to CRUD them
    | easily and fast. This is optional and is not needed
    | for your application.
    |
    */

    // Enable Optional Roles Gui
    'rolesGuiEnabled'               => env('ROLES_GUI_ENABLED', false),

    // Enable `auth` middleware
    'rolesGuiAuthEnabled'           => env('ROLES_GUI_AUTH_ENABLED', true),

    // Enable Roles GUI middleware
    'rolesGuiMiddlewareEnabled'     => env('ROLES_GUI_MIDDLEWARE_ENABLED', true),

    // Optional Roles GUI Middleware
    'rolesGuiMiddleware'            => env('ROLES_GUI_MIDDLEWARE', 'role:admin'),

    // User Permissions or Role needed to create a new role
    'rolesGuiCreateNewRolesMiddlewareType'   => env('ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE', 'role'), //permissions or roles
    'rolesGuiCreateNewRolesMiddleware'       => env('ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX

    // User Permissions or Role needed to create a new permission
    'rolesGuiCreateNewPermissionMiddlewareType'  => env('ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'role'), //permissions or roles
    'rolesGuiCreateNewPermissionsMiddleware'     => env('ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX

    // The parent blade file
    'bladeExtended'                 => env('ROLES_GUI_BLADE_EXTENDED', 'layouts.app'),

    // Blade Extension Placement
    'bladePlacement'                => env('ROLES_GUI_BLADE_PLACEMENT', 'yield'),
    'bladePlacementCss'             => env('ROLES_GUI_BLADE_PLACEMENT_CSS', 'inline_template_linked_css'),
    'bladePlacementJs'              => env('ROLES_GUI_BLADE_PLACEMENT_JS', 'inline_footer_scripts'),

    // Titles placement extend
    'titleExtended'                 => env('ROLES_GUI_TITLE_EXTENDED', 'template_title'),

    // Switch Between bootstrap 3 `panel` and bootstrap 4 `card` classes
    'bootstapVersion'               => env('ROLES_GUI_BOOTSTRAP_VERSION', '4'),

    // Additional Card classes for styling -
    // See: https://getbootstrap.com/docs/4.0/components/card/#background-and-color
    // Example classes: 'text-white bg-primary mb-3'
    'bootstrapCardClasses'          => env('ROLES_GUI_CARD_CLASSES', ''),

    // Bootstrap Tooltips
    'tooltipsEnabled'               => env('ROLES_GUI_TOOLTIPS_ENABLED', true),

    // jQuery
    'enablejQueryCDN'               => env('ROLES_GUI_JQUERY_CDN_ENABLED', true),
    'JQueryCDN'                     => env('ROLES_GUI_JQUERY_CDN_URL', 'https://code.jquery.com/jquery-3.3.1.min.js'),

    // Selectize JS
    'enableSelectizeJsCDN'          => env('ROLES_GUI_SELECTIZEJS_CDN_ENABLED', true),
    'SelectizeJsCDN'                => env('ROLES_GUI_SELECTIZEJS_CDN_URL', 'https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/js/standalone/selectize.min.js'),
    'enableSelectizeJs'             => env('ROLES_GUI_SELECTIZEJS_ENABLED', true),
    'enableSelectizeJsCssCDN'       => env('ROLES_GUI_SELECTIZEJS_CSS_CDN_ENABLED', true),
    'SelectizeJsCssCDN'             => env('ROLES_GUI_SELECTIZEJS_CSS_CDN_URL', 'https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/css/selectize.min.css'),

    // Font Awesome
    'enableFontAwesomeCDN'          => env('ROLES_GUI_FONT_AWESOME_CDN_ENABLED', true),
    'fontAwesomeCDN'                => env('ROLES_GUI_FONT_AWESOME_CDN_URL', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'),

    // Flash Messaging
    'builtInFlashMessagesEnabled'   => env('ROLES_GUI_FLASH_MESSAGES_ENABLED', true),

    /*
    |--------------------------------------------------------------------------
    | Laravel Roles API Settings
    |--------------------------------------------------------------------------
    |
    | This is the API for Laravel Roles to be able to CRUD them
    | easily and fast via an API. This is optional and is
    | not needed for your application.
    |
    */
    'rolesApiEnabled'               => env('ROLES_API_ENABLED', false),

    // Enable `auth` middleware
    'rolesAPIAuthEnabled'           => env('ROLES_API_AUTH_ENABLED', true),

    // Enable Roles API middleware
    'rolesAPIMiddlewareEnabled'     => env('ROLES_API_MIDDLEWARE_ENABLED', true),

    // Optional Roles API Middleware
    'rolesAPIMiddleware'            => env('ROLES_API_MIDDLEWARE', 'role:admin'),

    // User Permissions or Role needed to create a new role
    'rolesAPICreateNewRolesMiddlewareType'   => env('ROLES_API_CREATE_ROLE_MIDDLEWARE_TYPE', 'role'), //permissions or roles
    'rolesAPICreateNewRolesMiddleware'       => env('ROLES_API_CREATE_ROLE_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX

    // User Permissions or Role needed to create a new permission
    'rolesAPICreateNewPermissionMiddlewareType'  => env('ROLES_API_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'role'), //permissions or roles
    'rolesAPICreateNewPermissionsMiddleware'     => env('ROLES_API_CREATE_PERMISSION_MIDDLEWARE_TYPE', 'admin'), // admin, XXX. ... or perms.XXX

    /*
    |--------------------------------------------------------------------------
    | Laravel Roles GUI Datatables Settings
    |--------------------------------------------------------------------------
    */

    'enabledDatatablesJs'           => env('ROLES_GUI_DATATABLES_JS_ENABLED', false),
    'datatablesJsStartCount'        => env('ROLES_GUI_DATATABLES_JS_START_COUNT', 25),
    'datatablesCssCDN'              => env('ROLES_GUI_DATATABLES_CSS_CDN', 'https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css'),
    'datatablesJsCDN'               => env('ROLES_GUI_DATATABLES_JS_CDN', 'https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js'),
    'datatablesJsPresetCDN'         => env('ROLES_GUI_DATATABLES_JS_PRESET_CDN', 'https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js'),

    /*
    |--------------------------------------------------------------------------
    | Laravel Roles Package Integration Settings
    |--------------------------------------------------------------------------
    */

    'laravelUsersEnabled'           => env('ROLES_GUI_LARAVEL_ROLES_ENABLED', false),
];

Environment File

# Roles Default Models
ROLES_DEFAULT_USER_MODEL=App\User
ROLES_DEFAULT_ROLE_MODEL=jeremykenedy\LaravelRoles\Models\Role
ROLES_DEFAULT_PERMISSION_MODEL=jeremykenedy\LaravelRoles\Models\Permission

# Roles database information
ROLES_DATABASE_CONNECTION=null
ROLES_ROLES_DATABASE_TABLE=roles
ROLES_ROLE_USER_DATABASE_TABLE=role_user
ROLES_PERMISSIONS_DATABASE_TABLE=permissions
ROLES_PERMISSION_ROLE_DATABASE_TABLE=permission_role
ROLES_PERMISSION_USER_DATABASE_TABLE=permission_user

# Roles Misc Settings
ROLES_DEFAULT_SEPARATOR='.'

# Roles Database Migrations Settings
ROLES_MIGRATION_DEFAULT_ENABLED=true

# Roles Database Seeder Settings
ROLES_SEED_DEFAULT_PERMISSIONS=true
ROLES_SEED_DEFAULT_ROLES=true
ROLES_SEED_DEFAULT_RELATIONSHIPS=true
ROLES_SEED_DEFAULT_USERS=false

# Roles GUI Settings
ROLES_GUI_ENABLED=false
ROLES_GUI_AUTH_ENABLED=true
ROLES_GUI_MIDDLEWARE_ENABLED=true
ROLES_GUI_MIDDLEWARE='role:admin'
ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE='role'
ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE='admin'
ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE='role'
ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE='admin'
ROLES_GUI_BLADE_EXTENDED='layouts.app'
ROLES_GUI_TITLE_EXTENDED='template_title'
ROLES_GUI_LARAVEL_ROLES_ENABLED=false
ROLES_GUI_TOOLTIPS_ENABLED=true
ROLES_GUI_DATATABLES_JS_ENABLED=false

More Information

For more information, please have a look at HasRoleAndPermission contract.

Optional GUI Routes

+--------+-----------+---------------------------------+-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------+---------------------+
| Domain | Method    | URI                             | Name                                          | Action                                                                                                          | Middleware          |
+--------+-----------+---------------------------------+-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------+---------------------+
|        | GET|HEAD  | permission-deleted/{id}         | laravelroles::permission-show-deleted         | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                         | web,auth,role:admin |
|        | DELETE    | permission-destroy/{id}         | laravelroles::permission-item-destroy         | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                      | web,auth,role:admin |
|        | PUT       | permission-restore/{id}         | laravelroles::permission-restore              | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]            | web,auth,role:admin |
|        | POST      | permissions                     | laravelroles::permissions.store               | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                               | web,auth,role:admin |
|        | GET|HEAD  | permissions                     | laravelroles::permissions.index               | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                               | web,auth,role:admin |
|        | GET|HEAD  | permissions-deleted             | laravelroles::permissions-deleted             | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                        | web,auth,role:admin |
|        | DELETE    | permissions-deleted-destroy-all | laravelroles::destroy-all-deleted-permissions | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected] | web,auth,role:admin |
|        | POST      | permissions-deleted-restore-all | laravelroles::permissions-deleted-restore-all | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected] | web,auth,role:admin |
|        | GET|HEAD  | permissions/create              | laravelroles::permissions.create              | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                              | web,auth,role:admin |
|        | PUT|PATCH | permissions/{permission}        | laravelroles::permissions.update              | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                              | web,auth,role:admin |
|        | GET|HEAD  | permissions/{permission}        | laravelroles::permissions.show                | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                | web,auth,role:admin |
|        | DELETE    | permissions/{permission}        | laravelroles::permissions.destroy             | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                             | web,auth,role:admin |
|        | GET|HEAD  | permissions/{permission}/edit   | laravelroles::permissions.edit                | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                | web,auth,role:admin |
|        | GET|HEAD  | role-deleted/{id}               | laravelroles::role-show-deleted               | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                               | web,auth,role:admin |
|        | DELETE    | role-destroy/{id}               | laravelroles::role-item-destroy               | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                            | web,auth,role:admin |
|        | PUT       | role-restore/{id}               | laravelroles::role-restore                    | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                        | web,auth,role:admin |
|        | POST      | roles                           | laravelroles::roles.store                     | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                     | web,auth,role:admin |
|        | GET|HEAD  | roles                           | laravelroles::roles.index                     | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                     | web,auth,role:admin |
|        | GET|HEAD  | roles-deleted                   | laravelroles::roles-deleted                   | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                              | web,auth,role:admin |
|        | DELETE    | roles-deleted-destroy-all       | laravelroles::destroy-all-deleted-roles       | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]             | web,auth,role:admin |
|        | POST      | roles-deleted-restore-all       | laravelroles::roles-deleted-restore-all       | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]             | web,auth,role:admin |
|        | GET|HEAD  | roles/create                    | laravelroles::roles.create                    | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                    | web,auth,role:admin |
|        | DELETE    | roles/{role}                    | laravelroles::roles.destroy                   | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                   | web,auth,role:admin |
|        | PUT|PATCH | roles/{role}                    | laravelroles::roles.update                    | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                    | web,auth,role:admin |
|        | GET|HEAD  | roles/{role}                    | laravelroles::roles.show                      | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                      | web,auth,role:admin |
|        | GET|HEAD  | roles/{role}/edit               | laravelroles::roles.edit                      | jeremykenedy\LaravelRoles\App\Http\Controllers\[email protected]                                      | web,auth,role:admin |
+--------+-----------+---------------------------------+-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------+---------------------+

Screen Shots

Laravel Roles GUI Dashboard Laravel Roles GUI Create New Role Laravel Roles GUI Edit Role Laravel Roles GUI Show Role Laravel Roles GUI Delete Role Laravel Roles GUI Success Deleted Laravel Roles GUI Deleted Role Show Laravel Roles GUI Restore Role Laravel Roles GUI Delete Permission Laravel Roles GUI Show Permission Laravel Roles GUI Permissions Dashboard Laravel Roles GUI Create New Permission Laravel Roles GUI Roles Soft Deletes Dashboard Laravel Roles GUI Permissions Soft Deletes Dashboard Laravel Roles GUI Success Restore

File Tree

├── .env.example
├── .env.travis
├── .gitignore
├── .travis.yml
├── LICENSE
├── composer.json
├── phpunit.xml
├── readme.md
└── src
    ├── App
    │   ├── Exceptions
    │   │   ├── AccessDeniedException.php
    │   │   ├── LevelDeniedException.php
    │   │   ├── PermissionDeniedException.php
    │   │   └── RoleDeniedException.php
    │   ├── Http
    │   │   ├── Controllers
    │   │   │   ├── Api
    │   │   │   │   └── LaravelRolesApiController.php
    │   │   │   ├── LaravelPermissionsController.php
    │   │   │   ├── LaravelRolesController.php
    │   │   │   ├── LaravelRolesDeletedController.php
    │   │   │   └── LaravelpermissionsDeletedController.php
    │   │   ├── Middleware
    │   │   │   ├── VerifyLevel.php
    │   │   │   ├── VerifyPermission.php
    │   │   │   └── VerifyRole.php
    │   │   └── Requests
    │   │       ├── StorePermissionRequest.php
    │   │       ├── StoreRoleRequest.php
    │   │       ├── UpdatePermissionRequest.php
    │   │       └── UpdateRoleRequest.php
    │   └── Services
    │       ├── PermissionFormFields.php
    │       └── RoleFormFields.php
    ├── Contracts
    │   ├── HasRoleAndPermission.php
    │   ├── PermissionHasRelations.php
    │   └── RoleHasRelations.php
    ├── Models
    │   ├── Permission.php
    │   └── Role.php
    ├── RolesFacade.php
    ├── RolesServiceProvider.php
    ├── Traits
    │   ├── DatabaseTraits.php
    │   ├── HasRoleAndPermission.php
    │   ├── PermissionHasRelations.php
    │   ├── RoleHasRelations.php
    │   ├── RolesAndPermissionsHelpersTrait.php
    │   ├── RolesUsageAuthTrait.php
    │   └── Slugable.php
    ├── config
    │   └── roles.php
    ├── database
    │   ├── Migrations
    │   │   ├── 2016_01_15_105324_create_roles_table.php
    │   │   ├── 2016_01_15_114412_create_role_user_table.php
    │   │   ├── 2016_01_26_115212_create_permissions_table.php
    │   │   ├── 2016_01_26_115523_create_permission_role_table.php
    │   │   └── 2016_02_09_132439_create_permission_user_table.php
    │   └── Seeds
    │       ├── DefaultConnectRelationshipsSeeder.php
    │       ├── DefaultPermissionsTableSeeder.php
    │       ├── DefaultRolesTableSeeder.php
    │       ├── DefaultUsersTableSeeder.php
    │       └── publish
    │           ├── ConnectRelationshipsSeeder.php
    │           ├── PermissionsTableSeeder.php
    │           ├── RolesTableSeeder.php
    │           └── UsersTableSeeder.php
    ├── resources
    │   ├── lang
    │   │   └── en
    │   │       └── laravelroles.php
    │   └── views
    │       └── laravelroles
    │           ├── cards
    │           │   ├── permissions-card.blade.php
    │           │   └── roles-card.blade.php
    │           ├── crud
    │           │   ├── dashboard.blade.php
    │           │   ├── permissions
    │           │   │   ├── create.blade.php
    │           │   │   ├── deleted
    │           │   │   │   └── index.blade.php
    │           │   │   ├── edit.blade.php
    │           │   │   └── show.blade.php
    │           │   └── roles
    │           │       ├── create.blade.php
    │           │       ├── deleted
    │           │       │   └── index.blade.php
    │           │       ├── edit.blade.php
    │           │       └── show.blade.php
    │           ├── forms
    │           │   ├── create-permission-form.blade.php
    │           │   ├── create-role-form.blade.php
    │           │   ├── delete-sm.blade.php
    │           │   ├── destroy-all-permissions.blade.php
    │           │   ├── destroy-all-roles.blade.php
    │           │   ├── destroy-sm.blade.php
    │           │   ├── edit-permission-form.blade.php
    │           │   ├── edit-role-form.blade.php
    │           │   ├── partials
    │           │   │   ├── permission-desc-input.blade.php
    │           │   │   ├── permission-name-input.blade.php
    │           │   │   ├── permission-slug-input.blade.php
    │           │   │   ├── permissions-model-select.blade.php
    │           │   │   ├── role-desc-input.blade.php
    │           │   │   ├── role-level-input.blade.php
    │           │   │   ├── role-name-input.blade.php
    │           │   │   ├── role-permissions-select.blade.php
    │           │   │   └── role-slug-input.blade.php
    │           │   ├── permission-form.blade.php
    │           │   ├── restore-all-permissions.blade.php
    │           │   ├── restore-all-roles.blade.php
    │           │   ├── restore-item.blade.php
    │           │   └── role-form.blade.php
    │           ├── modals
    │           │   └── confirm-modal.blade.php
    │           ├── partials
    │           │   ├── bs-visibility-css.blade.php
    │           │   ├── flash-messages.blade.php
    │           │   ├── form-status.blade.php
    │           │   └── styles.blade.php
    │           ├── scripts
    │           │   ├── confirm-modal.blade.php
    │           │   ├── datatables.blade.php
    │           │   ├── form-inputs-helpers.blade.php
    │           │   ├── selectize.blade.php
    │           │   ├── selectizePermission.blade.php
    │           │   └── tooltips.blade.php
    │           └── tables
    │               ├── permission-items-table.blade.php
    │               ├── permissions-table.blade.php
    │               ├── role-items-table.blade.php
    │               └── roles-table.blade.php
    └── routes
        ├── api.php
        └── web.php
  • Tree command can be installed using brew: brew install tree
  • File tree generated using command tree -a -I '.git|node_modules|vendor|storage|tests'

Opening an Issue

Before opening an issue there are a couple of considerations:

  • You are all awesome!
  • Read the instructions and make sure all steps were followed correctly.
  • Check that the issue is not specific to your development environment setup.
  • Provide duplication steps.
  • Attempt to look into the issue, and if you have a solution, make a pull request.
  • Show that you have made an attempt to look into the issue.
  • Check to see if the issue you are reporting is a duplicate of a previous reported issue.
  • Following these instructions show me that you have tried.
  • If you have a questions send me an email to [email protected]
  • Need some help, I can do my best on Slack: https://opensourcehelpgroup.slack.com
  • Please be considerate that this is an open source project that I provide to the community for FREE when opening an issue.

Credit Note:

The HasRoleAndPermission Trait And Contract is and an adaptation of romanbican/roles. I liked the method he made so I used them.

License

This package is free software distributed under the terms of the MIT license. Enjoy!

Comments
  • Php artisan migrate and seed not working accordingly

    Php artisan migrate and seed not working accordingly

    I have fresh install Laravel 5.8 and then I change the inside of RolesTableSeeder.php into this: image

    and then when I run the php artisan migrate:fresh --seed, it run the seed on different files

    image

    invalid non supporter 
    opened by jeraldpunx 18
  • Use a nother guard instead of auth

    Use a nother guard instead of auth

    First take a look at the following

    1. https://github.com/jeremykenedy/laravel-roles#opening-an-issue
    2. https://github.com/jeremykenedy/laravel-roles/issues?q=is%3Aissue+is%3Aclosed

    Please describe what you are needing help with below: Great package, I'm working on a multi-tenant application where i use multi guard so how to use a specific guard instead of auth guard. Thanks

    opened by dukenst2006 11
  • RoleDeniedException not being caught...

    RoleDeniedException not being caught...

    Thanks Jeremy for this awesome package.

    I have followed the steps and verified numerous times, however I am having an issue when logged in as a User with only the User role, and trying to go to: /users

    I am expecting the RoleDeniedException to be thrown and handled cleanly, as per the updates suggested to the Handler.php file.

    Looking at the logs, I can definitely see that the RoleDeniedException is being thrown:

    [2018-08-17 08:06:41] local.ERROR: You don't have a required ['admin'] role. {"userId":3,"email":"[email protected]","exception":"[object] (jeremykenedy\\LaravelRoles\\Exceptions\\RoleDeniedException(code: 0): You don't have a required ['admin'] role. at /Library/WebServer/www/vgsmart/vendor/jeremykenedy/laravel-roles/src/Middleware/VerifyRole.php:42)
    [stacktrace]
    #0 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): jeremykenedy\\LaravelRoles\\Middleware\\VerifyRole->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'admin')
    #1 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #2 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #3 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #4 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #5 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(43): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #6 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #7 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #8 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(68): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #9 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #10 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #11 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #12 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #13 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #14 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #15 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #16 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #17 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #18 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #19 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #20 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #21 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #22 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #23 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #24 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Router.php(667): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
    #25 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Router.php(642): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
    #26 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Router.php(608): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
    #27 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Router.php(597): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
    #28 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
    #29 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
    #30 /Library/WebServer/www/vgsmart/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #31 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #32 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #33 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #34 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #35 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #36 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #37 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #38 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #39 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #40 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #41 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #42 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #43 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #44 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #45 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #46 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
    #47 /Library/WebServer/www/vgsmart/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
    #48 /Library/WebServer/www/vgsmart/public/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
    #49 {main}
    "}
    
    image

    I am using the absolute latest, fresh install of Laravel 5.6.

    Any direction would be appreciated.

    Thanks mate.

    Nathan

    opened by nathangoss 10
  • Permission and Roles cannot be Deleted.

    Permission and Roles cannot be Deleted.

    First take a look at the following

    1. https://github.com/jeremykenedy/laravel-roles#opening-an-issue
    2. https://github.com/jeremykenedy/laravel-roles/issues?q=is%3Aissue+is%3Aclosed

    Describe the bug permission and roles delete button and modal not working its giving javascript error.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by shehroz-myglu 8
  • Incorrect Table Name ''

    Incorrect Table Name ''

    `Migrating: 2016_01_15_114412_create_role_user_table

    Illuminate\Database\QueryException

    SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: alter table roleUserTable add constraint roleusertable_role_id_foreign foreign key (role_id) references `` (id) on delete cascade)

    at C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671 667| // If an exception occurs when attempting to run a query, we'll format the error 668| // message to include the bindings with SQL, which will make this exception a 669| // lot more helpful to the developer instead of just the database's errors. 670| catch (Exception $e) {

    671| throw new QueryException( 672| $query, $this->prepareBindings($bindings), $e 673| ); 674| } 675|

    1 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:464 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''")

    2 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:464 PDOStatement::execute()`

    opened by jcrann 7
  • GUI does not work

    GUI does not work

    I enabled GUI and cleaned my cache. When I go to url prjectname/roles page coming as blank

    .env file

    # Roles GUI Settings
    ROLES_GUI_ENABLED=true
    ROLES_GUI_AUTH_ENABLED=true
    ROLES_GUI_MIDDLEWARE_ENABLED=true
    ROLES_GUI_MIDDLEWARE='role:admin'
    ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE='role'
    ROLES_GUI_CREATE_ROLE_MIDDLEWARE_TYPE='admin'
    ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE='role'
    ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE='admin'
    ROLES_GUI_BLADE_EXTENDED='layouts.app'
    ROLES_GUI_TITLE_EXTENDED='template_title'
    ROLES_GUI_LARAVEL_ROLES_ENABLED=true
    ROLES_GUI_TOOLTIPS_ENABLED=true
    ROLES_GUI_DATATABLES_JS_ENABLED=true
    

    Laravel version 5.8

    I did following command. but no luck

    composer dump-autoload
    php artisan config:clear
    php artisan config:cache
    
    opened by shankar-bavan 7
  • Package Migrations can not be overwrite

    Package Migrations can not be overwrite

    Hi @jeremykenedy we have error by trying migrate custom role_user migrations, because always the migration system takes the package migrations and not our custom migrations. How can i to configure the package to take my custom migrations?, i need this because we using multiple databases.

    Regards!

    invalid non supporter 
    opened by JohanMa4 7
  • Controller Middleware not working

    Controller Middleware not working

    I am trying to do something like this in my constructor with no success:

    $this->middleware('role:premium.user'); $this->middleware('role:tenant.user')->only('index');

    The php artisan route:list command shows the middleware in the routes i need it, but i got a 403 in the routes.

    Laravel documentation: https://laravel.com/docs/5.7/controllers#controller-middleware

    supporter 
    opened by shalemperez 7
  • Foreign Key Constraint Error (Users References)

    Foreign Key Constraint Error (Users References)

    In Laravel 5.8 create users table migration use **

    $table->bigIncrements('id');

    ** which is causing Foreign key constraint error on role_user table & permission_user table.

    However converting: **

    $table->bigIncrements('id');

    **

    TO

    **

    $table->increments('id');

    ** will fix the problem.

    non supporter 
    opened by shaheryartvs 7
  • how to create new role

    how to create new role

    laravel 5.5 | vagrant/homestead

    Hello, I would like you to help me explain how I can create a new role, and associate x permissions to that role, I saw the documentation of laravel-roles but I did not understand, thanks in advance

    question wontfix 
    opened by lCHECHOl 7
  • HasRolesAndPermissions rolePermissions() is missing 'deleted_at' in its groupBy

    HasRolesAndPermissions rolePermissions() is missing 'deleted_at' in its groupBy

    Hello !

    Just tried this awesome looking package for laravel ( thanks ! ) according to my composer.lock, i'm using 2.0.1

    Quickly first, the database seeds aren't working out of the box, saying that the seeder classes were not found.. had to remove the namespace Database\Seeders to have it working. ( note that php artisan make:seed creates a new file without any namespace )

    Then seeding works but still not for UsersTableSeeder I'd get a Syntax error or access violation: 1055 'mydb.permissions.deleted_at' isn't in GROUP BY

    narrowed it down to the HasRoleAndPermission->rolePermissions() method.. as the sql error said, simply adding 'permissions.deleted_at' to the groupBy fixed it for me:

    trait HasRoleAndPermission
    {
        [ ... ]
    
        public function rolePermissions()
        {
            $permissionModel = app(config('roles.models.permission'));
    
            if (!$permissionModel instanceof Model) {
                throw new InvalidArgumentException('[roles.models.permission] must be an instance of \Illuminate\Database\Eloquent\Model');
            }
    
            return $permissionModel
                ::select(['permissions.*', 'permission_role.created_at as pivot_created_at', 'permission_role.updated_at as pivot_updated_at'])
                ->join('permission_role', 'permission_role.permission_id', '=', 'permissions.id')
                ->join('roles', 'roles.id', '=', 'permission_role.role_id')
                ->whereIn('roles.id', $this->getRoles()->pluck('id')->toArray())
                ->orWhere('roles.level', '<', $this->level())
                ->groupBy(['permissions.id', 'permissions.name', 'permissions.slug', 'permissions.description', 'permissions.model', 'permissions.created_at', 'permissions.updated_at', 'permissions.deleted_at', 'pivot_created_at', 'pivot_updated_at' ]);
        }
    
        [ ... ]
    }
    

    .. now, back to enjoying this package :)

    non supporter 
    opened by aftek 6
  • included dependency of eklundkristoffer/seedster breaks default artisan db:seed command

    included dependency of eklundkristoffer/seedster breaks default artisan db:seed command

    > artisan db:seed --class=CustomClassSeeder

    is broken by the included eklundkristoffer/seedster so i get an

    Illuminate\Contracts\Container\BindingResolutionException
    
    Target class [CustomClassSeeder] does not exist.
    

    i've created an pull request there to quick fix: https://github.com/eklundkristoffer/seedster/pull/7

    But i'm not sure if it will be included and the overwriting of the core functionality there may be some bad behavior? May be there could used some other solution?

    opened by pprossi 0
  • n+1 tests

    n+1 tests

    Note:

    • Replaced echo in seeders with command output
    • Deferred seeders registration after resolving seed.handler to prevent errors
    • Updated legacy phpunit.xml

    Still cannot reproduce #179

    Detected problem: cannot preload rolePermissions and userPermissions. rolePermissions is not relation at all and cannot be preloaded via eager load

    opened by ulcuber 0
  • N+1 happening after PR #171

    N+1 happening after PR #171

    First take a look at the following

    • [x] https://github.com/jeremykenedy/laravel-roles#opening-an-issue
    • [x] https://github.com/jeremykenedy/laravel-roles/issues?q=is%3Aissue+is%3Aclosed

    Describe the bug After PR #171 was merged and the new code hit the wild with laravel-roles v8.1.0 for L9, the project I'm working with has been plagued with N+1 warnings from beyondcode/laravel-query-detector. What's interesting is that the purpose of the referred PR is to fix N+1 queries. But see:

    [2022-03-18 13:21:17] app.INFO: [BEGIN] UserStoreUpdateControllerTest  
    [2022-03-18 13:21:18] app.INFO: testUpdate N+1  
    [2022-03-18 13:21:18] app.INFO: Detected N+1 Query  
    [2022-03-18 13:21:18] app.INFO: Model: App\Models\User
    Relation: App\Models\Role
    Num-Called: 2
    Call-Stack:
    #19 /vendor/jeremykenedy/laravel-roles/src/Traits/HasRoleAndPermission.php:49
    #20 /vendor/jeremykenedy/laravel-roles/src/Traits/HasRoleAndPermission.php:145
    #21 /app/Http/Controllers/Admin/UserUpdateController.php:123
    

    If I manually revert Traits\HasRoleAndPermission->getRoles() to the old code (i.e. before PR #171)...

    public function getRoles()
    {
        return (!$this->roles) ? $this->roles = $this->roles()->get() : $this->roles;
    }
    

    ...then N+1 queries are gone. I'm still trying to isolate the issue, so I don't have a solution to propose just yet.

    For the record, this is the relevant bits in /app/Http/Controllers/Admin/UserUpdateController.php:

    # Replaces jeremykenedy\laravelusers\App\Http\Controllers\UsersManagementController::update();
    
    namespace App\Http\Controllers\Admin;
    
    class UserUpdateController extends Controller
    {
        public function __invoke(Request $request, int $id): RedirectResponse
        {
            $rolesEnabled = config('laravelusers.rolesEnabled');
            $user = config('laravelusers.defaultUserModel')::find($id);
            ...
            if ($rolesEnabled) {
                $user->detachAllRoles();
                $user->attachRole($request->input('role')); #21 UserUpdateController.php:123 from stack trace
            }
            ...
            return redirect('users')
                ->with('success', trans('laravelusers::laravelusers.messages.update-user-success'));
        }
    }
    

    User Model:

    namespace App\Models;
    
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use jeremykenedy\LaravelRoles\Traits\HasRoleAndPermission;
    
    class User extends Authenticatable
    {
        use HasRoleAndPermission;
        ...
    }
    

    To Reproduce

    1. Install beyondcode/laravel-query-detector;
    2. Override UsersManagementController::update();
    3. Update a user or run a test on the new method;
    4. Look for N+1 messages as configured by laravel-query-detector.

    Expected behavior Get rid of N+1 queries.

    Screenshots N/A

    Desktop (please complete the following information):

    • OS: Slackware 15 (Linux kernel 5.16.15), PHP 8.1.3, Laravel 9.5.1, Laravel Roles 8.1.0
    • Browser: Vivaldi
    • Version: 5.1.2567.66 (Stable channel) stable (64 bits) (Chrome/98.0.4758.136)

    Smartphone (please complete the following information): N/A

    Additional context N/A

    opened by denydias 1
  • Doesn't exclude roles were deleted

    Doesn't exclude roles were deleted

    Hi, In trait HasRoleAndPermission, I have error when use function rolePermissions() return all permissions of roles included roles were deleted.

    Thanks,

    bug help wanted 
    opened by starofsky 0
Releases(v9.0.0)
  • v9.0.0(Sep 9, 2022)

    What's Changed

    • Removing vcs from composer by @rafaelqm in https://github.com/jeremykenedy/laravel-roles/pull/178
    • fixed: allow to override route middlewares via Kernel by @ulcuber in https://github.com/jeremykenedy/laravel-roles/pull/184
    • Fix database seeder publish path by @abhishekpaul in https://github.com/jeremykenedy/laravel-roles/pull/181

    New Contributors

    • @abhishekpaul made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/181

    Full Changelog: https://github.com/jeremykenedy/laravel-roles/compare/v8.1.0...v9.0.0

    Important Note:

    You will need to

    'route_middlewares' => true,

    to your the roles.php config file. https://github.com/jeremykenedy/laravel-roles/blob/master/src/config/roles.php

    Source code(tar.gz)
    Source code(zip)
  • v8.1.0(Feb 20, 2022)

    What's Changed

    • Update eklundkristoffer/seedster to a release with Laravel 9 support. by @denydias in https://github.com/jeremykenedy/laravel-roles/pull/177

    New Contributors

    • @denydias made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/177

    Full Changelog: https://github.com/jeremykenedy/laravel-roles/compare/v8.0.0...v8.1.0

    Source code(tar.gz)
    Source code(zip)
  • v8.0.0(Feb 17, 2022)

    What's Changed

    • Update .env.example by @maxdestors in https://github.com/jeremykenedy/laravel-roles/pull/170
    • Update description of composer.json with support of laravel 8.0 by @maxdestors in https://github.com/jeremykenedy/laravel-roles/pull/169
    • fixed: roles n+1 queries by @ulcuber in https://github.com/jeremykenedy/laravel-roles/pull/171
    • Update documentation on Exception Handling Laravel 8 Compatibility by @ruelluna in https://github.com/jeremykenedy/laravel-roles/pull/172
    • Adding support to Laravel 9 by @rafaelqm in https://github.com/jeremykenedy/laravel-roles/pull/176
    • Laravel 9.x Compatibility by @laravel-shift in https://github.com/jeremykenedy/laravel-roles/pull/173

    New Contributors

    • @ulcuber made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/171
    • @ruelluna made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/172
    • @rafaelqm made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/176
    • @laravel-shift made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/173

    Full Changelog: https://github.com/jeremykenedy/laravel-roles/compare/v7.0.0...v8.0.0

    Source code(tar.gz)
    Source code(zip)
  • v7.0.0(Nov 25, 2021)

    Resolves bugs and includes community enhancements.

    Thank you everyone!

    • https://github.com/jeremykenedy/laravel-roles/issues/161
    • https://github.com/jeremykenedy/laravel-roles/pull/166
    • https://github.com/jeremykenedy/laravel-roles/pull/164
    • https://github.com/jeremykenedy/laravel-roles/pull/163
    • https://github.com/jeremykenedy/laravel-roles/pull/152

    What's Changed

    • doubled condition by @nekhbet in https://github.com/jeremykenedy/laravel-roles/pull/152
    • Add optional prefix to GUI routes by @bynicolas in https://github.com/jeremykenedy/laravel-roles/pull/163
    • custom table name error by @tmali16 in https://github.com/jeremykenedy/laravel-roles/pull/164
    • Fix VerifyRole and VerifyPermission to work with comma separated values by @maxdestors in https://github.com/jeremykenedy/laravel-roles/pull/166
    • Apply fixes from StyleCI by @jeremykenedy in https://github.com/jeremykenedy/laravel-roles/pull/167

    New Contributors

    • @nekhbet made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/152
    • @bynicolas made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/163
    • @tmali16 made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/164
    • @maxdestors made their first contribution in https://github.com/jeremykenedy/laravel-roles/pull/166

    Full Changelog: https://github.com/jeremykenedy/laravel-roles/compare/v6.0.0...v7.0.0

    Source code(tar.gz)
    Source code(zip)
  • v6.0.0(Mar 26, 2021)

  • v5.1.0(Jan 2, 2021)

  • v5.0.0(Jan 2, 2021)

    Note this release might have some breaking changes because a config option was added.

    You will need to republish the config file or add the following line to your roles.php config file:

    'inheritance' => env('ROLES_INHERITANCE', true),
    

    See: https://github.com/jeremykenedy/laravel-roles/blob/master/src/config/roles.php#L65

    Thank you @andreasmatu and @sdonchez for these updates.

    Source code(tar.gz)
    Source code(zip)
  • v4.0.0(Sep 21, 2020)

  • v3.8.0(Sep 21, 2020)

  • v3.7.0(Sep 21, 2020)

  • v3.6.0(Sep 21, 2020)

  • v3.5.0(Sep 21, 2020)

  • v3.4.0(Aug 4, 2020)

  • v3.3.0(Jul 28, 2020)

  • v3.2.1(May 30, 2020)

  • v3.2.0(May 26, 2020)

  • v3.1.1(May 23, 2020)

  • v3.1.0(May 23, 2020)

  • v3.0.1(May 23, 2020)

  • v3.0.0(Mar 3, 2020)

  • v2.9.0(Mar 3, 2020)

  • v2.8.0(Mar 3, 2020)

  • v2.7.0(Mar 3, 2020)

  • v2.6.0(Mar 3, 2020)

  • v2.5.0(Dec 18, 2019)

Owner
Jeremy Kenedy
Love programming everyday. Practice compassion and kindness to all. Striving to be a better person and father. Love giving back and helping others.
Jeremy Kenedy
This is a lightweight package that allows you assign roles and permissions to any Laravel model, or on a pivot table (many to many relationship).

Simple Laravel roles and permissions Introduction This package allows you to assign roles and permissions to any laravel model, or on a pivot table (m

null 52 Nov 10, 2022
Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system.

Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system. Built on Bootstrap 4.

Jeremy Kenedy 2.8k Dec 31, 2022
Tech-Admin is Laravel + Bootstrap Admin Panel With User Management And Access Control based on Roles and Permissions.

Tech-Admin | Laravel 8 + Bootstrap 4 Tech-Admin is Admin Panel With Preset of Roles, Permissions, ACL, User Management, Profile Management. Features M

TechTool India 39 Dec 23, 2022
Handle roles and permissions in your Laravel application

Laratrust (Laravel Package) Version Compatibility Laravel Laratrust 8.x 6.x 7.x 6.x 6.x 6.x 5.6.x - 5.8.x 5.2 5.3.x - 5.5.x 5.1 5.0.x - 5.2.x 4.0. Ins

Santiago García 2k Dec 30, 2022
Laravel Roles and Permissions

Introduction to Laravel Roles and Permission App Starter Kit Roles and sanctions are a paramount part of many web applications. In project, we have op

Brian Kiprono Koech 1 Nov 1, 2021
Roles & Permissions for Laravel 8 / 7 / 6 / 5

Defender Defender is an Access Control List (ACL) Solution for Laravel 5 / 6 / 7 (single auth). (Not compatible with multi-auth) With security and usa

Artesãos 437 Dec 22, 2022
Laravel Users (Roles & Permissions, Devices, Password Hashing, Password History).

LARAVEL USERS Roles & Permissions Devices Password Hashing Password History Documentation You can find the detailed documentation here in Laravel User

Pharaonic 8 Dec 14, 2022
Associate users with roles and permissions

Associate users with permissions and roles Sponsor If you want to quickly add authentication and authorization to Laravel projects, feel free to check

Spatie 10.9k Jan 3, 2023
This package helps you to associate users with permissions and permission groups with laravel framework

Laravel ACL This package allows you to manage user permissions and groups in a database, and is compatible with Laravel v5.8 or higher. Please check t

Mateus Junges 537 Dec 28, 2022
PermissionsMakr is a Laravel package that will help any developer to easily manage the system's users permissions

PermissionsMakr is a Laravel package that will help any developer to easily manage the system's users permissions

Alvarium Digital 3 Nov 30, 2021
Eloquent roles and abilities.

Bouncer Bouncer is an elegant, framework-agnostic approach to managing roles and abilities for any app using Eloquent models. Table of Contents Click

Joseph Silber 3.2k Jan 5, 2023
GUI manager for RBAC (Role Base Access Control) Yii2. Easy to manage authorization of user

RBAC Manager for Yii 2 GUI manager for RBAC (Role Base Access Control) Yii2. Easy to manage authorization of user ?? . Documentation Important: If you

MDMunir Software 1.2k Jan 7, 2023
Proyecto para aprender a utilizar privilegios (roles y permisos) con CRUDBooster

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Informática DP 3 May 9, 2022
Role-based Permissions for Laravel 5

ENTRUST (Laravel 5 Package) Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5. If you are looking for the Laravel 4 ve

Zizaco 6.1k Jan 5, 2023
Light-weight role-based permissions system for Laravel 6+ built in Auth system.

Kodeine/Laravel-ACL Laravel ACL adds role based permissions to built in Auth System of Laravel 8.0+. ACL middleware protects routes and even crud cont

Kodeine 781 Dec 15, 2022
Manage authorization with granular role-based permissions in your Laravel Apps.

Governor For Laravel Manage authorization with granular role-based permissions in your Laravel apps. Goal Provide a simple method of managing ACL in a

GeneaLabs, LLC 149 Dec 23, 2022
Laravel mongodb permissions

Laravel mongodb permissions

null 4 May 10, 2022
💝The Plus (ThinkSNS+) is a powerful, easy-to-develop social system built with Laravel.

Plus (ThinkSNS+) Plus (ThinkSNS+) 是使用 Laravel 框架开发;一个功能强大、易于开发和动态拓展的社交系统。Plus 是遵循 PSR 规范 代码统一,并功能块松耦合。你安装完成 Plus 并不意味着已经成功安装了所有功能,因为 Plus 使用 模块化 的 原则,

Slim Kit 2.2k Jan 3, 2023
A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package

laravel-social A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package. I

Sergi Tur Badenas 42 Nov 29, 2022