spatie/laravel-permission

getRoleNames returns empty array for user

sts-ryan-holton opened this issue · 2 comments

Describe the bug

I have roles in my database which are linked to my companies. A user has been assigned a role through a company, but when querying the user's roles, nothing is returned other than an empty array.

I've read the documentation on this one, surely this is a bug?

Versions

  • spatie/laravel-permission package version: 8.7.0
  • illuminate/framework package 9.46.0

PHP version: 8.1.0

Database version: MySQL

Additional context

$roles = User::find(Auth::id())->getRoleNames();

return response()->json([
    'roles' => $roles
], 200);

Roles table:

Screenshot 2023-01-10 at 15 14 07

Model has roles table

Screenshot 2023-01-10 at 15 14 29

It don't looks like a bug, looks like you don't understand the basics for using team_id feature

#1992 (comment)
#2209 (comment)
#2121 (comment)

Also this could help
#2075

I've read the documentation on this one

Also read other issues/discussions before opening a new one every few minutes

spatie/laravel-permission package version: 8.7.0

Latest is 5.7