Laravel-permission: Confused? Role does not exist?

Created on 5 May 2017  路  9Comments  路  Source: spatie/laravel-permission

I created 3 basic roles to test with...

Role::create(['guard_name' => 'super-admin', 'name' => 'superadmin']);
Role::create(['guard_name' => 'admin', 'name' => 'admin']);
Role::create(['guard_name' => 'user', 'name' => 'user']);

I assigned the role during a debug test...

auth()->loginUsingId(1);

auth()->user()->assignRole('admin');

// Error retrieved...
RoleDoesNotExist in RoleDoesNotExist.php line 11:
There is no role named admin.

There is clearly a role named 'admin' and the 'guard-name' is also 'admin'

Why can't I find it?

screen shot 2017-05-05 at 12 56 45 pm

Most helpful comment

I had the same issue and have figured out the solution and i.e.

First add "protected $guard_name = 'api';" in User.php (Model file).
image

Then, Change your field guard_name to "api" in your roles table as shown in screenshot below.
image

Enjoy Coding :)
Feel Free to Reply for any issues regarding this.

All 9 comments

Additional Comment: I have already gone through and performed the clear cache as it stated as well... just in case :D

From what I can gather...

it's using the guard 'web' in my whoops debugger:
Role::findByName('admin', 'web')

oh, I think I see what the reasoning is for this... testing in a second and I will delete if I figured it out :D

@SeoRoman Have you resolved your issue?

@SeoRoman What have you set as your guard_name? I was facing the same issue until I set it as 'web'. I believe it's beacuse that is the default guard set on 'auth.php'

@ChiefScript Check latest comments in issue #276

I had the same issue and have figured out the solution and i.e.

First add "protected $guard_name = 'api';" in User.php (Model file).
image

Then, Change your field guard_name to "api" in your roles table as shown in screenshot below.
image

Enjoy Coding :)
Feel Free to Reply for any issues regarding this.

@sushantDev Thank you soo much it's working...(after searching many googling ;-) )

I had the same issue and have figured out the solution and i.e.

First add "protected $guard_name = 'api';" in User.php (Model file).
image

Then, Change your field guard_name to "api" in your roles table as shown in screenshot below.
image

Enjoy Coding :)
Feel Free to Reply for any issues regarding this.

I love you

I had the same issue and have figured out the solution and i.e.

First add "protected $guard_name = 'api';" in User.php (Model file).
image

Then, Change your field guard_name to "api" in your roles table as shown in screenshot below.
image

Enjoy Coding :)
Feel Free to Reply for any issues regarding this.

Hi.. I got there is no permission named some permission for guard `api, any idea?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichalKrakow picture MichalKrakow  路  4Comments

neoreids picture neoreids  路  3Comments

enghelewa picture enghelewa  路  4Comments

vpratfr picture vpratfr  路  4Comments

bhulsman picture bhulsman  路  3Comments