Laravel-permission: hasPermissionTo works but can isnt working

Created on 22 Feb 2017  路  5Comments  路  Source: spatie/laravel-permission

Hello,

For some reason can isnt working on the user, but hasPermissionTo does work.
I prefer can because is uses cached permissions.

I have set the cache to database and there arent any cache rows created for the permissions.
Any ideas what could be wrong?

Kind regards,

Erwin

Most helpful comment

This is the same caching issue as #231. You can use the following command to flush your cache and resolve the issue:

php artisan cache:forget spatie.permission.cache 

Good luck!

All 5 comments

The permissions are registered at the gate in this function

It will put an exception in your log if for some reason it's unable to register those permissions.

Do you see a notice in your log? If not, try to determine if that function is being called.

I see that it's checking the database if there are any rows in the cache table.

select * from cache where key = 'mlmspatie.permission.cache' limit 1

And then it's trying to update a row. But there arent any rows in the cache table. So it keeps retrieving alle the permissions from the database.

I have checked the laravel.log file but that one is empty.

Could you try installing the package in a vanilla Laravel app and test if it works there?

Yep same for me...

Role Permissions:
access.backend
view.properties
create.properties
edit.properties
view.clients
create.clients
edit.clients

Direct Permissions: none

All Permissions:
access.backend
view.properties
create.properties
edit.properties
view.clients
create.clients
edit.clients

(at)can('view.sliders') => true
auth()->user()->hasPermissionTo('view.sliders') => false

This is the same caching issue as #231. You can use the following command to flush your cache and resolve the issue:

php artisan cache:forget spatie.permission.cache 

Good luck!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ionesculiviucristian picture ionesculiviucristian  路  4Comments

feliperoan picture feliperoan  路  3Comments

bbdangar picture bbdangar  路  4Comments

neoreids picture neoreids  路  3Comments

younus93 picture younus93  路  4Comments