laravel-acl
laravel-acl copied to clipboard
collisions in using traits
in laravel 5.1.11 your HasRole trait have collisions with laravel embed traits because in this version of laravel acl system is added check this out
I think I have the same problem
use Kodeine\Acl\Traits\HasRole;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, HasRole;
in php artisan tinker I've this message
[Symfony\Component\Debug\Exception\FatalErrorException]
Trait method can has not been applied, because there are collisions with other trait methods on App\User
maybe this fix?
use Authenticatable, Authorizable, CanResetPassword, HasRole {
HasRole::can insteadof Authorizable;
}
but i'm a newbie...
same here
So how you guys solve this?
Like i've said i've solved using this in class User, I don't know if is the best solution but works
use Authenticatable, Authorizable, CanResetPassword, HasRole {
HasRole::can insteadof Authorizable;
}
So far I used
use Authenticatable, CanResetPassword, HasRole; instead of //use Authenticatable, Authorizable, CanResetPassword;
use Kodeine\Acl\Traits\HasRole;
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract { use Authenticatable, CanResetPassword, HasRole;
it will fix your issue
I think it's wrong to override the laravel gate instead do this:
use ...., HasRole {
Authorizable::can insteadof HasRole;
HasRole::can as havePermission;
}
as the can() is more appropriate in the gate service because the end point of really determinate if user can do some action is inside the gate can where you could do like:
$gate->define('update-post', function ($user, $post) {
if ($user->id !== $post->user_id) return false;
if (!$user->havePermission('update-post) return false;
return true;
});
as you can see if you name the method can is not true because a user can have permission of update post, but the post maybe not belong to him, so the "can" name should belong to the gate as it the end point of really saying if you can or can't do something
@kodeine
The workaround to map the clashing method to a new method should at least be mentioned in the documentation IMO.