Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nklss's avatar
Level 1

Spatie Laravel - Permissions and Roles are not applied, no matter what I do

Hi community!

I'm dealing with a very strange issue regarding the Laravel package Laravel-Permissions from Spatie (v 5.10.0). I've successfully installed the package using Composer2 by following the official guide. And did all further steps, described as follows:

  • Added the service provider to config/app.php file
  • Published Vendor files (config/permission.php)
  • Cleared cached configuration ($ php artisan config:clear)
  • Migrated necessary scheme ($ php artisan migrate)
  • Added the trait HasRoles the user model

After that I've created a role called admin and applied that role to my user account:

  • Entry from "roles" table ......... id: 1 / name: admin / guard_name: web
  • Entry from "model_has_roles" table ...... role_id: 1 / model_type: App\User / model_id: 10
  • Entry from "users" table: ...... id: 10

Expected behaviour

Role has been set and can be used in routes.php and in blade views as well using something like:

  • auth()->user()->hasRole('admin')

Current behaviour

  • Dump result of the code snippet above is always false, also after deleting the package's cache.

Do you have any ideas what I can do? I've used the package a couple of times and never had such issues.

Thanks, wish you a nice day! nklss

0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104
model_type: App\User

Did you manually add this record; the FQCN (by default) should be App\Models\User

1 like
nklss's avatar
Level 1

@tykus You are awesome, many thanks!

This was exactly the issue. When I last used the package, models were created directly in the Http directory and not in the separate Models directory (which was introduced in Laravel 9 I guess?).

tykus's avatar

@nklss the models directory (and namespace) was (re)introduced in Laravel v8

2 likes

Please or to participate in this conversation.