It seems that the laravel "can" methods are not working with this package. I've just done a fresh install again, run the make:auth and then followed the setup instructions for this package and found that the issue is still the same.
In short I expect the following two lines of code to do pretty much the same thing:
$user->hasPermissionTo('edit articles');
and
$user->can('edit articles');
However, the hasPermissionTo() method works perfectly while the can() method always returns false.
To test this, I did a fresh install, ran the make:auth and ran the spatie/laravel-permission setup. I then added a new user with a role of "role" and permission of "test". The Permission was linked to the role on the role_has_permissions table.
I then ran this from the routes.php
$user = App\User::find(1);
if ( $user->can('test'))
{
echo '<h2>User Can "TEST" </h2>';
}
else
{
echo '<h2>User Cannot "TEST"</h2>';
}
if ( $user->hasPermissionTo('test'))
{
echo '<h2>User Has Permission To "TEST" </h2>';
}
else
{
echo '<h2>User Does Not have permission to "TEST"</h2>';
}
The output on screen was
User Cannot "TEST"
User Has Permission To "TEST"
Please can someone explain if my expectations were correct? Or if there is something that I'm missing?
From reading the documentation, I thought that this would plug in perfectly with the existing laravel features.
The tests seem to confirm that can is working. Please add a failing test if the problems persist.
@dylanharbour I have had the same issue. Try deleting everything in storage/framework/cache folder. In my case 'php artisan cache:clear' didn't do anything, so I manually deleted those files and it started working.
From my experience (not so long) file permissions on system cause 95% of all of the problems, and 5% are typos. So I tend to first try with 'sudo chmod -R 777 storage/ bootstrap/cache/' and if that doesn't help - find the typo!
It took me a lot of time to realize that php artisan cache:clear will not work and I need to deleted any folder in storage/framework/cache manually. Every thing is working very well. You made my day. Thanks @ergonomicus.
Most helpful comment
It took me a lot of time to realize that
php artisan cache:clearwill not work and I need to deleted any folder instorage/framework/cachemanually. Every thing is working very well. You made my day. Thanks @ergonomicus.