Code Monkey home page Code Monkey logo

roles-permissions's Introduction

Simple Wrapper to implement Roles & Permissions in Laravel

Pre Requisites

  • PHP >= v7.3
  • Laravel >= 6.0
  • Composer Dependency Manager v1.8.4 or greater

Project Setup

  • Clone or fork the project on your machine. https://github.com/usamamuneerchaudhary/roles-permissions.git
  • Install all dependencies by running the following command in project root directory composer install
  • Rename .env.example to .env by running the following command mv .env.example .env
  • Configure DB settings in your .env file
  • Run php artisan key:generate to generate application key.
  • Run DB migrations by php artisan migrate
  • Congrats, you're all set up & ready to go.

Optional steps

  • Run DB migrations with sample seeders php artisan migrate --seed or php artisan migrate:refresh --seed

roles-permissions's People

Contributors

dependabot-preview[bot] avatar richardevcom avatar usamamuneerchaudhary 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

Watchers

 avatar  avatar  avatar  avatar  avatar

roles-permissions's Issues

Trying to get property 'roles' of non-object

when I use $user->hasPermissionTo('create-buyer'); it's return Trying to get property 'roles' of non-object error.

when using dd($user->can('create-buyer')); it's returning always false

any fix for 'permissions table not found' on seed?

When I run composer dump and php artisan migrate --seed I get the following message:

PermissionServiceProvider is throwing 'permissions table not found' error.

It only works if I manually uncomment the following in app.php config: "App\Providers\PermissionsServiceProvider::class".

Thanks

Just wanted to thank you.
This is the first Article that made me understand Laravel Gate's properly and in an useful way

Cheers

Error - Call to a member function hasRole() on null - in \app\Http\Middleware\RoleMiddleware.php

When I'm logged out and I access /admin URL I get Call to a member function hasRole() on null error.

If the user is not logged in, there is no user data to process, so we need to throw 404 code.

Full error message:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function hasRole() on null
…\app\Http\Middleware\RoleMiddleware.php
Line 21

To fix this error you should add this snippet on top of the handle() method:

if(is_null($request->user())){
      abort(404);
}

I've submited this fix. Please approve.

hasRole returns null in collection

hasRole returns null in collection whereas data exist in users_roles and roles table
dd($user->hasRole( 'admin'));

and when i dd($this->roles); it returns me empty collection which lead always return false on
foreach ($roles as $role) { if ($this->roles->contains('slug', $role)) { return true; } }

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.