GithubHelp home page GithubHelp logo

jeremykenedy / laravel-roles Goto Github PK

View Code? Open in Web Editor NEW
925.0 42.0 189.0 349 KB

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

License: MIT License

PHP 56.25% Blade 43.75%
laravel-roles-permissions laravel-roles laravel-permissions laravel-acl acl-management roles-management user-levels permissions laravel acl

laravel-roles's Introduction

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:

<?php

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.

<?php

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  \Throwable  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Throwable $e)
	{
		$userLevelCheck = $e instanceof \jeremykenedy\LaravelRoles\App\Exceptions\RoleDeniedException ||
			$e instanceof \jeremykenedy\LaravelRoles\App\Exceptions\PermissionDeniedException ||
			$e 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, $e);
	}

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.
<?php

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\LaravelpermissionsDeletedController@show                         | web,auth,role:admin |
|        | DELETE    | permission-destroy/{id}         | laravelroles::permission-item-destroy         | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelpermissionsDeletedController@destroy                      | web,auth,role:admin |
|        | PUT       | permission-restore/{id}         | laravelroles::permission-restore              | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelpermissionsDeletedController@restorePermission            | web,auth,role:admin |
|        | POST      | permissions                     | laravelroles::permissions.store               | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelPermissionsController@store                               | web,auth,role:admin |
|        | GET|HEAD  | permissions                     | laravelroles::permissions.index               | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelPermissionsController@index                               | web,auth,role:admin |
|        | GET|HEAD  | permissions-deleted             | laravelroles::permissions-deleted             | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelpermissionsDeletedController@index                        | web,auth,role:admin |
|        | DELETE    | permissions-deleted-destroy-all | laravelroles::destroy-all-deleted-permissions | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelpermissionsDeletedController@destroyAllDeletedPermissions | web,auth,role:admin |
|        | POST      | permissions-deleted-restore-all | laravelroles::permissions-deleted-restore-all | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelpermissionsDeletedController@restoreAllDeletedPermissions | web,auth,role:admin |
|        | GET|HEAD  | permissions/create              | laravelroles::permissions.create              | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelPermissionsController@create                              | web,auth,role:admin |
|        | PUT|PATCH | permissions/{permission}        | laravelroles::permissions.update              | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelPermissionsController@update                              | web,auth,role:admin |
|        | GET|HEAD  | permissions/{permission}        | laravelroles::permissions.show                | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelPermissionsController@show                                | web,auth,role:admin |
|        | DELETE    | permissions/{permission}        | laravelroles::permissions.destroy             | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelPermissionsController@destroy                             | web,auth,role:admin |
|        | GET|HEAD  | permissions/{permission}/edit   | laravelroles::permissions.edit                | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelPermissionsController@edit                                | web,auth,role:admin |
|        | GET|HEAD  | role-deleted/{id}               | laravelroles::role-show-deleted               | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesDeletedController@show                               | web,auth,role:admin |
|        | DELETE    | role-destroy/{id}               | laravelroles::role-item-destroy               | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesDeletedController@destroy                            | web,auth,role:admin |
|        | PUT       | role-restore/{id}               | laravelroles::role-restore                    | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesDeletedController@restoreRole                        | web,auth,role:admin |
|        | POST      | roles                           | laravelroles::roles.store                     | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesController@store                                     | web,auth,role:admin |
|        | GET|HEAD  | roles                           | laravelroles::roles.index                     | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesController@index                                     | web,auth,role:admin |
|        | GET|HEAD  | roles-deleted                   | laravelroles::roles-deleted                   | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesDeletedController@index                              | web,auth,role:admin |
|        | DELETE    | roles-deleted-destroy-all       | laravelroles::destroy-all-deleted-roles       | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesDeletedController@destroyAllDeletedRoles             | web,auth,role:admin |
|        | POST      | roles-deleted-restore-all       | laravelroles::roles-deleted-restore-all       | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesDeletedController@restoreAllDeletedRoles             | web,auth,role:admin |
|        | GET|HEAD  | roles/create                    | laravelroles::roles.create                    | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesController@create                                    | web,auth,role:admin |
|        | DELETE    | roles/{role}                    | laravelroles::roles.destroy                   | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesController@destroy                                   | web,auth,role:admin |
|        | PUT|PATCH | roles/{role}                    | laravelroles::roles.update                    | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesController@update                                    | web,auth,role:admin |
|        | GET|HEAD  | roles/{role}                    | laravelroles::roles.show                      | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesController@show                                      | web,auth,role:admin |
|        | GET|HEAD  | roles/{role}/edit               | laravelroles::roles.edit                      | jeremykenedy\LaravelRoles\App\Http\Controllers\LaravelRolesController@edit                                      | 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!

laravel-roles's People

Contributors

abhishekpaul avatar aftek avatar andreasmatuszewski avatar ashurali avatar bynicolas avatar cf-git avatar denydias avatar ekawas avatar ivan-cc avatar jeremykenedy avatar kentdahl avatar laravel-shift avatar marcnewton avatar maxdestors avatar michaelgatuma avatar nekhbet avatar oyepez003 avatar rafaelqm avatar ricardoboss avatar ruelluna avatar sdonchez avatar sharafat avatar stylecibot avatar sudwebdesign avatar tmali16 avatar totha avatar ulcuber avatar vinicio328 avatar vitalyevrica avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-roles's Issues

How do you get a list all the permission for a specific role?

Hi jeremy,
I like to thank you for sharing this amazing package.
But i want to ask how to get all the permissions for a specific role. For example let say i want get all the permission for a role who's slug is xyz or maybe id is 10. How can i do so ?

I saw in HasRoleAndPermission trait there is a function rolePermissions but not sure how to use that : |

I tried with this

 $role=Role::where('id',$id)->first();
$data['pemissions'] = $role->rolePermissions ();

But that throwing badmethodcall exception .
Can you please tell me how can i get all the permission assign to a role ?

Thanks

great work .. can i use it for a production application ?

it's a real world implementation,
i loved the levels feature, giving permission to both role and user, and clear documentation.

another question is it possible to check multi roles or permissions in middleware?

thanks in advance,,

Auth::user()->hasPermission('view-users') giving error

(2/2) QueryException
SQLSTATE[42000]: Syntax error or access violation: 1055 'baseappnew.permissions.status' isn't in GROUP BY (SQL: select permissions.*, permission_role.created_at as pivot_created_at, permission_role.updated_at as pivot_updated_at from permissions inner join permission_role on permission_role.permission_id = permissions.id inner join roles on roles.id = permission_role.role_id where roles.id in (1) or roles.level < 5 group by permissions.id, permissions.name, permissions.slug, permissions.description, permissions.model, permissions.created_at, permissions.updated_at, pivot_created_at, pivot_updated_at)

Anyway to get the permission slugs for vuejs

I am trying to integrate the permissions with vuejs and currently return just the roles in id form.

"roles": [
        {
            "id": 1,
            "name": "Admin",
            "slug": "admin",
            "description": "Admin",
            "level": 5,
            "created_at": "2019-01-28 02:47:03",
            "updated_at": "2019-01-28 02:47:03",
            "pivot": {
                "user_id": 1,
                "role_id": 1,
                "created_at": "2019-01-28 02:47:07",
                "updated_at": "2019-01-28 02:47:07"
            }
        }
    ]

Is there a way to add these in the User model, or perhaps the AuthServiceProvider boot.

Something like...

$user = User::with('roles')->first();
$roleId = $user->roles[0]->id;
$roles = Role::select('id', 'slug')->with('permissions')->where('id', $roleId)->first();

Cant create role;

When i try to assign role i get this error code:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'eve.role_user' doesn't exist (SQL: select roles.*, role_user.user_eve_id as pivot_user_eve_id, role_user.role_id as pivot_role_id, role_user.created_at as pivot_created_at, role_user.updated_at as pivot_updated_at from roles inner join role_user on roles.id = role_user.role_id where role_user.user_eve_id = 2113243644)

and yes, i`m not use basic users table

Comparison to spatie/laravel-permission

just wondering how this package compares to spatie/laravel-permission?

The other package has been running for a long time, has many contributions and many eyes on it to keep it up-to-date and compatible with new versions of Laravel. My personal approach is never to reinvent the wheel where-ever possible. So does this package offer anything that spatie/laravel-permission does not?

Class role does not exist

Using Laravel v. 5.6.7 with your laravel-users and laravel-roles extensions installed. make:auth has been executed as well as the associated migrations. (No other extensions installed except for what came with the initial install.) I've been over your instructions for installation for both extensions multiple times. I can't find anything that I've left off, but each time I try to go to http:///users, I get this mysterious ReflectionException (-1) Class role does not exist. Of course, the exception doesn't point to any specific place where the exception originates, except for the Illuminate classes. Ditto for the laravel.log.

I've no doubt that I'm missing something. I'm hoping that you can point me in the right direction.

Slow application ??

i have navbar it dependence on role and permission
is there a solution to speed application and reduce server resource to go to database to check permission ??

Return individual user roles and permissions in the same api call?

This relates to issue #25

I have managed to get it working by using the api call on login and set the roles with vue.js

this.$store.state.user;

But is there a way of returning permissions as well roles in the same api call? Currently roles work fine.

Route::get('/user', function (Request $request) {
    return $request->user()->with('roles')->find($request->user()->id);
})->middleware('auth:api');

update to support Laravel 5.8

Hi Jeremy,

I'm seeing this error on composer:

  Problem 1
    - Installation request for jeremykenedy/laravel-roles ^1.3 -> satisfiable by jeremykenedy/laravel-roles[v1.3.0].
    - Conclusion: remove laravel/framework v5.8.2
    - Conclusion: don't install laravel/framework v5.8.2
    - jeremykenedy/laravel-roles v1.3.0 requires laravel/framework 5.3.*|5.4.*|5.5.*|5.6.*|5.7.* -> satisfiable by laravel/framework[5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev].
    - Can only install one of: laravel/framework[5.6.x-dev, v5.8.2].
    - Can only install one of: laravel/framework[5.7.x-dev, v5.8.2].
    - Can only install one of: laravel/framework[5.3.x-dev, v5.8.2].
    - Can only install one of: laravel/framework[5.4.x-dev, v5.8.2].
    - Can only install one of: laravel/framework[5.5.x-dev, v5.8.2].
    - Installation request for laravel/framework (locked at v5.8.2, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.2].

Are you aware of this? Maybe the package needs to be updated to 1.4 after you updated the composer.json file? I cleared my local composer cache.

And a side question. Do you see use for the new Eloquent HasOneThrough Relationship in Laravel-Roles?

Thanks! :)

GUI Attach User

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

Is your feature request related to a problem? Please describe.
nope

Describe the solution you'd like
The GUI to manage roles and permissions is perfect, but the only one things we can't do, is manage user to attach them to a Roles.

Describe alternatives you've considered
i have installed laravel-users but we can't do this.

$user->can('permission')->for($project)

Hi

I have a web app in development which provides a niche service, and I want to implement something not unlike a programme management hierarchy.

|- Customer (entity) A
|- ...
|- Customer (entity) X
     |
     |- Programme Owner A (role/permission?)
     |- ...
     |- Programme Owner E (role/permission?)
           |
           |- Project E1
           |- ...
           |- Project E5
                 |
                 |- Manager of E5 (role/permission?) 
                 |- Assignee 1 of E5 (role/permission?)
                 |- ...
                 |- Assignee n of E5 (role/permission?)

Here is how I think it might work out, and I wonder if this package can handle it, or if there's another one, what it is. Or how to extend this one!

  • Mary, a user "M" becomes a Member (role: Member)
  • User M can optionally become a Customer (handled by customers table, fk etc, all good so far)
  • If User M is a customer, then they may create a Programme
  • User M still has the "member" role, but now also has an additional role, as owner "owner" of Programme P
  • Programme owners may create Projects per Programme and may assign work to other users to wok on certain Stuff, on a per project basis.
  • For example, Bob, a new User "B" joins, and through some steps, User M wishes to Promote User B to Manager of one of the Projects in her Programme.
  • We would then have a need to describe certain permissions such as (pseudo-coded),
    $user->withRole('owner')->for(programme $programme)->can("promote user to project manager")->for(project $project)

So now, I will need to be able to represent this somehow in my app. That User B has the role of manager, but only for one project inside Programme P which is owned by User M. In all other scenarios User B is just a plain old member.

This would allow me to create a sort of marketplace where users can be available to perform tasks on the platform in a sort of freelance way. Any use may become a customer. be assigned work by any other customer and only be able to access their own programmes and any assignments assigned by other members.

Any pointers how to do this with your package (or alternatives) will be appreciated - thanks.

Getting permissions per user object

When I attach role to user and use $user->roles, I get all roles that are attached to that user.
But when I attach permission to user, I do get connection in permission_user table but when I use $user->permissions I get null always.

I can get only all permissions by using $user->getPermissions(), but those are all within permission_user table and those from roles relations.

Is that supposed to work like that or not? Thanks

Can't save new permissions or roles

Hi, as the title says, i can't save a new role or permissions. It apperars that is passing a empty string to the id field and i can't figure out the problem. I'm kind of new in laravel so any help would be appreciated.
Screenshot_20190620_160256

Roles GUI css and js implantation is outside of html

When i enable roles gui then see my source code - i see bootstrap file import, css class, js file import and js script are outside of html code.
Code Like this :

 
 
  <style type="text/css" media="screen">
  .no-padding {
  padding: 0;
  }
  .pointer {
  cursor: pointer;
  }
  .card {
  width: 100%;
  }
  .modal .modal-header {
  -webkit-border-top-left-radius: .2rem;
  -webkit-border-top-right-radius: .2rem;
  -moz-border-radius-topleft: .2rem;
  -moz-border-radius-topright: .2rem;
  border-top-left-radius: .2rem;
  border-top-right-radius: .2rem;
  }
  .modal-success .modal-header {
  color: #ffffff;
  background-color: #5cb85c;
  }
  .modal-warning .modal-header {
  color:#fff;
  background-color: #f0ad4e;
  }
  .modal-danger .modal-header {
  color:#fff;
  background-color: #d9534f;
  }
  .modal-info .modal-header {
  color:#fff;
  background-color: #5bc0de;
  }
  .modal-primary .modal-header {
  color:#fff;
  background-color: #428bca;
  }
  .blocked-table {
  border: 0;
  }
  .blocked-table tr td:first-child {
  padding-left: 15px;
  }
  .blocked-table tr td:last-child {
  padding-right: 15px;
  }
  .blocked-table.table-responsive,
  .blocked-table.table-responsive table {
  margin-bottom: 0;
  }
  .clickable-row:hover {
  cursor: pointer;
  }
  .blocked-table.table-responsive {
  border: none;
  }
  .blocked-table .list-group {
  margin-bottom: 0;
  }
  .blocked-table .dropdown-menu > li button {
  padding: 3px 20px;
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  }
  .blocked-table .dropdown-menu > li button:hover {
  background: rgba(0,0,0,.04);
  }
   
  .blocked-table {
  border: 0;
  }
  .blocked-table tr th {
  border: 0 !important;
  }
  .blocked-table tr th:first-child,
  .blocked-table tr td:first-child {
  padding-left: 15px;
  }
  .blocked-table tr th:last-child,
  .blocked-table tr td:last-child {
  padding-right: 15px;
  }
  .blocked-table .table-responsive,
  .blocked-table .table-responsive table {
  margin-bottom: 0;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  }
  .blocked-table .data-table {
  width: 100%;
  }
  .btn-save,
  .pw-change-container {
  display: none;
  }
  .has-error,
  .has-error input,
  .has-error select,
  .has-error textarea {
  border-color: #d9534f;
  }
  .clear-search {
  display: none;
  }
  div.dataTables_wrapper div.dataTables_length label {
  margin-top: 5px;
  margin-bottom: 5px;
  margin-right:20px;
  }
  div.dataTables_wrapper div.dataTables_length label select {
  margin-left: 5px;
  margin-right: 5px
  }
  #search_blocked_form {
  display: none;
  }
  .disabled {
  color: #dcdbdb;
  pointer-events: none;
  cursor: not-allowed;
  }
  .disabled .switch span.active {
  color: #dcdbdb;
  pointer-events: none;
  cursor: not-allowed;
  }
  .accordion.accordion-item {
  cursor: pointer;
  cursor: zoom-out;
  }
  .accordion.accordion-item.collapsed {
  cursor: zoom-in;
  }
  .accordion.accordion-item .permission-name:before,
  .accordion.accordion-item .role-name:before {
  font-family: 'FontAwesome';
  content: "\f068";
  margin: 0 .5em 0 0;
  }
  .accordion.accordion-item.collapsed .permission-name:before,
  .accordion.accordion-item.collapsed .role-name:before {
  content: "\f067";
  }
  .list-group-item table {
  font-size: .5em;
  width: 100%;
  display: table;
  table-layout: fixed;
  }
  .permissions-table,
  .roles-table {
  font-size: .9em;
  }
  .table.permissions-table thead th,
  .table.permissions-table td,
  .table.roles-table thead th,
  .table.roles-table td {
  border: none;
  vertical-align: middle;
  }
  .table.permissions-table form,
  .table.roles-table form {
  margin: 0;
  }
  @media(min-width: 576px) {
  .edit-form-delete {
  margin-top: -2.85em;
  }
  }
  </style>
  <style type="text/css" media="screen">
  .visible-xs,
  .visible-sm,
  .visible-md,
  .visible-lg {
  display: none !important;
  }
  .visible-xs-block,
  .visible-xs-inline,
  .visible-xs-inline-block,
  .visible-sm-block,
  .visible-sm-inline,
  .visible-sm-inline-block,
  .visible-md-block,
  .visible-md-inline,
  .visible-md-inline-block,
  .visible-lg-block,
  .visible-lg-inline,
  .visible-lg-inline-block {
  display: none !important;
  }
  @media (max-width: 767px) {
  .visible-xs {
  display: block !important;
  }
  table.visible-xs {
  display: table !important;
  }
  tr.visible-xs {
  display: table-row !important;
  }
  th.visible-xs,
  td.visible-xs {
  display: table-cell !important;
  }
  }
  @media (max-width: 767px) {
  .visible-xs-block {
  display: block !important;
  }
  }
  @media (max-width: 767px) {
  .visible-xs-inline {
  display: inline !important;
  }
  }
  @media (max-width: 767px) {
  .visible-xs-inline-block {
  display: inline-block !important;
  }
  }
  @media (min-width: 768px) and (max-width: 991px) {
  .visible-sm {
  display: block !important;
  }
  table.visible-sm {
  display: table !important;
  }
  tr.visible-sm {
  display: table-row !important;
  }
  th.visible-sm,
  td.visible-sm {
  display: table-cell !important;
  }
  }
  @media (min-width: 768px) and (max-width: 991px) {
  .visible-sm-block {
  display: block !important;
  }
  }
  @media (min-width: 768px) and (max-width: 991px) {
  .visible-sm-inline {
  display: inline !important;
  }
  }
  @media (min-width: 768px) and (max-width: 991px) {
  .visible-sm-inline-block {
  display: inline-block !important;
  }
  }
  @media (min-width: 992px) and (max-width: 1199px) {
  .visible-md {
  display: block !important;
  }
  table.visible-md {
  display: table !important;
  }
  tr.visible-md {
  display: table-row !important;
  }
  th.visible-md,
  td.visible-md {
  display: table-cell !important;
  }
  }
  @media (min-width: 992px) and (max-width: 1199px) {
  .visible-md-block {
  display: block !important;
  }
  }
  @media (min-width: 992px) and (max-width: 1199px) {
  .visible-md-inline {
  display: inline !important;
  }
  }
  @media (min-width: 992px) and (max-width: 1199px) {
  .visible-md-inline-block {
  display: inline-block !important;
  }
  }
  @media (min-width: 1200px) {
  .visible-lg {
  display: block !important;
  }
  table.visible-lg {
  display: table !important;
  }
  tr.visible-lg {
  display: table-row !important;
  }
  th.visible-lg,
  td.visible-lg {
  display: table-cell !important;
  }
  }
  @media (min-width: 1200px) {
  .visible-lg-block {
  display: block !important;
  }
  }
  @media (min-width: 1200px) {
  .visible-lg-inline {
  display: inline !important;
  }
  }
  @media (min-width: 1200px) {
  .visible-lg-inline-block {
  display: inline-block !important;
  }
  }
  @media (max-width: 767px) {
  .hidden-xs {
  display: none !important;
  }
  }
  @media (min-width: 768px) and (max-width: 991px) {
  .hidden-sm {
  display: none !important;
  }
  }
  @media (min-width: 992px) and (max-width: 1199px) {
  .hidden-md {
  display: none !important;
  }
  }
  @media (min-width: 1200px) {
  .hidden-lg {
  display: none !important;
  }
  }
  .visible-print {
  display: none !important;
  }
  @media print {
  .visible-print {
  display: block !important;
  }
  table.visible-print {
  display: table !important;
  }
  tr.visible-print {
  display: table-row !important;
  }
  th.visible-print,
  td.visible-print {
  display: table-cell !important;
  }
  }
  .visible-print-block {
  display: none !important;
  }
  @media print {
  .visible-print-block {
  display: block !important;
  }
  }
  .visible-print-inline {
  display: none !important;
  }
  @media print {
  .visible-print-inline {
  display: inline !important;
  }
  }
  .visible-print-inline-block {
  display: none !important;
  }
  @media print {
  .visible-print-inline-block {
  display: inline-block !important;
  }
  }
  @media print {
  .hidden-print {
  display: none !important;
  }
  }
  </style>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script type="text/javascript">
  $(function() {
  // Confirm Form Submit Modal
  $('#confirmDelete').on('show.bs.modal', function (e) {
  var message = $(e.relatedTarget).attr('data-message');
  var title = $(e.relatedTarget).attr('data-title');
  var form = $(e.relatedTarget).closest('form');
  $(this).find('.modal-body p').text(message);
  $(this).find('.modal-title').text(title);
  $(this).find('.modal-footer #confirm').data('form', form);
  });
  $('#confirmDelete').find('.modal-footer #confirm').on('click', function(){
  $(this).data('form').submit();
  });
  });
  </script>
  <script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  <script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
  <script type="text/javascript">
  $(document).ready(function() {
  $('.data-table').dataTable({
  "order": [[0]],
  "pageLength": 100,
  "lengthMenu": [
  [10, 25, 50, 100, 500, 1000, -1],
  [10, 25, 50, 100, 500, 1000, "All"]
  ], "paging": true,
  "lengthChange": true,
  "searching": true,
  "ordering": true,
  "info": true,
  "autoWidth": false,
  "dom": 'T<"clear">lfrtip',
  "sPaginationType": "full_numbers",
  'aoColumnDefs': [{
  'bSortable': false,
  'searchable': false,
  'aTargets': ['no-search'],
  'bTargets': ['no-sort']
  }]
  });
  });
  </script>
  <script type="text/javascript">
  $(document).ready(function(){
  var is_touch_device = 'ontouchstart' in document.documentElement;
  if (!is_touch_device) {
  $('[data-toggle="tooltip"]').tooltip();
  }
  });
  </script>
   
 
 
 
 
 
   
 
 
   
  <title>Laravel</title>
 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
 
 

Use GUI management

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:

hi,

i have update my .env with this variable to enable GUI. i have
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='administrators'
ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE='role'
ROLES_GUI_CREATE_PERMISSION_MIDDLEWARE_TYPE='administrators'
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

but my question is, can i use your project to manage user, role, permission like your printscreen, without make it from scratch ?

because when i add this configuration on my .env, i can't acces to the route 127.0.0.1/permissions or anything else in http get.

i use laravel 5.8.

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!

Class 'App\UserRole' not found

I'm using Laravel 5.8 and just added this package to my project. I tried to add the section that adds the user and the role on registration and I'm getting an issue. Laravel is stating that

Class 'App\UserRole' not found

Occurred in vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasRelationships.php on line 720.

Has anyone else had this issue and been able to solve it?

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.

HasRoleAndPermission not found

hi,
I try to use this feature, but after implementation I have this error:

FatalErrorException in User.php line 13: Trait 'jeremykenedy\LararvelRoles\Traits\HasRoleAndPermission' not found

this is my User.php

Check role in Vue Page

Is there a way to check what role is currently logged-in in a Vue page like it was shown for blade pages?

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

Middleware return to view

How do i return a user to a view if he doesn't have the required role?

public function render($request, Exception $exception)
    {
        $userLevelCheck = $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\RoleDeniedException ||
            $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\RoleDeniedException ||
            $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\PermissionDeniedException ||
            $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\LevelDeniedException;

        if ($userLevelCheck) {

            $page = array(
                'name' => 'Dashboard'
            );
            
            return view('home')->with('page', $page);
        }

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

This gives me a "Call to a member function setCookie() on null" error and i can't seem to fix it am i doing something wrong?

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 :)

Custom user and roles structure

Hi there,

I have an existing architecture that is highly extended and customized from Laravel Auth. I want to use your package, but how roles and permissions get associated are not from User but rather from my association of organization+user, as detailed below.

My structure looks like this:

Tables:
organization
user
role
organization_user
organizatin_user_role

High level relationships:
organization_user
|- organization
|- user

organization_user_role
|- organization_user_id
|- role_id

My table pkids are also not incrementing integers but rather prefixed guid v4 values.

I guess my question is this - I think your package for managing and assigning roles and permissions is much more flexible and intuitive than others I've seen. But I need to make a number of changes to support my architecture in order to get your package to work. I just don't want to have to re-invent the wheel. Do you have any issue with me doing this with your package? This will not be publicly distributed and will ONLY be used by our internal systems. I will maintain credit to you within our code for this package, but I'll be creating my own (internally in our own repo) just based on yours.

Question: role inheritance

Does your package support role inheritance (admin is also a user and thus inherits all user permissions) outside the level settings ?
Or do I have to determine the levels and is there no inheritance for roles or permissions?

After update I get migration error

Hi. I recently run composer update on my project. then I run artisan migrate command and got:

Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table role_useradd constraintrole_user_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

i looked up the source and see that RolesServiceProvider.php has this line:

$this->loadMigrationsFrom(__DIR__.'/Database/Migrations');

which i think couses the error.

I switched back to previous version of package, but its limiting some features.

Laravel Framework 5.6.39

Question for multiple roles

Question: Paired with your user management extension, is there a simple way to enable multiple role selection on the create/edit form. The default showing is 1, and I can't find a trait or similar listed to enable multiple roles on the blade templates.

I noticed the form didn't have:
multiple="multiple"

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.