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

alex_hill's avatar

spatie/laravel-permission - clearing cache does not appear to refresh permissions

I am testing out the spatie/laravel-permission package and am having similar issue to others in terms of cache. I have tried the following three commands, none of them seem to make a difference:

php artisan cache:clear
php artisan config:cache
php artisan cache:forget spatie.permission.cache

Then using the following code I get a PermissionDoesNotExist error (There is no permission named test for guard web)

public function test()
    {
        dd(auth()->user()->hasPermissionTo('test'));
    }

I can clearly see the test permission in the database. Similarly when I run the same code over a permission that was previously linked the the user's role, but has since been removed, the code returns true.

Is there another way to clear the cache, or even better turn permission caching off completely for testing purposes?

0 likes
10 replies
igorash's avatar

I assume there's a bug with the cache really... I've done all type of cache clears (all of the above) and still have the same error...

igorash's avatar

It doesn't work like that:

dd(auth()->user()->hasPermissionTo('test'));

But is does work if you pass permission as object:

$permission = \Spatie\Permission\Models\Permission::whereName('test')->first();
dd(auth()->user()->hasPermissionTo($permission))
1 like
AndyFTP's avatar

I was having the same problem (laravel 5.5), tried everything to clear the cache, now i changed my cache to database cache and i see the key saved as laravelspatie.permission.cache, just like all other keys are being prefixed with laravel so i went to see config/cache.php, turns out theres a setting that prefixes cache keys, by default the prefix is set to laravel, so using:

php artisan cache:forget laravelspatie.permission.cache

might work.

1 like
sl0wik's avatar

Make sure you don't have a case where cache files are made by www user and you trying to remove them as another user.

nasirkhan's avatar

i was facing the same issue for last 2 days. like the @alex_hill i tried all the known commands and nothing worked. then suddenly i tred the sudo php artisan cache:clear and it was working afterwards.

spiagz's avatar

To manually reset the cache for this package, you can run the following artisan command

php artisan permission:cache-reset

1 like
nisarr's avatar

It might be a permissions issue. run

sudo php artisan permission:cache-reset
1 like

Please or to participate in this conversation.