entrust
entrust copied to clipboard
Laravel 5.1.11 - Trait method can has not been applied, because there are collisions with other trait methods on App\User
It appears that the new Authorizable trait also has a can method. I have temporarily resolved it using may instead which I believe is grammatically more correct anyway.
use Authenticatable, CanResetPassword, PresentableTrait, Authorizable, EntrustUserTrait {
EntrustUserTrait::can as may;
Authorizable::can insteadof EntrustUserTrait;
}
Also got the same error. @whoacowboy Don't you think you approach will cause some error down the line when using the package
It's a temp fix, I updated the issue. I actually think that Taylor is planning on building roles and permissions into a later release so it won't be much of an issue going forward. I wish he'd just incorporate Entrust and make my life easy.
follow
@whoacowboy 's solution worked, but when I attach a role to a user like so:
$user->attachRole('1');
// or
$user->roles()->attach('1');
This error occurs:
BadMethodCallException in Builder.php line 2025:
Call to undefined method Illuminate\Database\Query\Builder::attach()

Hey @doncadavona, I am unable to reproduce this issue.
php artisan tinker
>>> $role1 = \App\Role::find(1);
>>> $role2 = \App\Role::find(2);
>>> $user = \App\User::find(32);
>>> $user->attachRole($role1);
>>> $user->roles()->attach($role2);
database checks out.
Have you tried composer dump-autoload
?
Does attach and attachRole need an int
instead of a string
?
$user->attachRole(1);
// or
$user->roles()->attach(1);
Are you using any other packages or traits that touch User
?
Face palm, Just realized Entrust isn't compatible with Laravel 5.1. Entrust conflicts with Laravel 5.1's new built-in Authorization in 5.1: http://laravel.com/docs/5.1/authorization. I didn't realize Laravel had Authorization in 5.1 until now. Is it a goodbye to Entrust?
I don;t think Laravel 5.1 have Role/Permissions things. Have you check
use Zizaco\Entrust\Traits\EntrustUserTrait;
public function roles();
at Users Model ?
@doncadavona Laravel still doesn't have roles and permissions, but I suspect it is coming in the near future, maybe 5.1.29
maybe.. maybe probably never have . Is the problem solved?
At 2015-09-24 03:04:48, "James" [email protected] wrote:
@doncadavona Laravel still doesn't have roles and permissions, but I suspect it is coming in the near future, maybe 5.1.29
— Reply to this email directly or view it on GitHub.
Another possible solution would be to just remove "use Authorizable" from the User Model, since we are using Entrust in place of Laravel's default. Setting this up on a current project will notify if I run into any issues
Like @kilrizzy said, use Authorizable
must be removed.
You can just replace this:
// ...
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
// ...
with the following:
// ...
use Zizaco\Entrust\Traits\EntrustUserTrait;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable;
use CanResetPassword;
use EntrustUserTrait;
// ...
I suggest updating the README and closing this issue.
pedzed solution worked for me
@pedzed solution works well for Laravel 5.1.
@pedzed Thanks, it worked :)
@pedzed removing Authorizable will make gate stops working...
@pedzed removing Authorizable will make gate stops working...
I know. You should either use Entrust or Laravel 5.1.11's built-in Authorization (http://laravel.com/docs/5.1/authorization). Why would you use both?
@pedzed Laravel's built-in is different from entrust.. it`s not checking if user has role X .. it's mostly permissions not role... i mixed both by on the policy class calling something like this
return $user->hasRole('admin')
in built in laravel u would need to check against something
return $user->id === $something->id
Laravel's built-in is different from entrust.. it`s not checking if user has role X .. it's mostly permissions not role... i mixed both by on the policy class calling something like this
return $user->hasRole('admin')
in built in laravel u would need to check against something
return $user->id === $something->id
I know, but in my opinion, if you use Entrust, you don't need Laravel's Authorization. But if it's really something you want, you could work around it by writing your own code.
It'd be better if this can be added to readme.md
This working for me. Thanks @pedzed
class User extends Model implements AuthenticatableContract,
//AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable,
//Authorizable,
EntrustUserTrait,
CanResetPassword;
conflicts with use SoftDeletes;
Trait method restore has not been applied, because there are collisions with other trait methods on App\User
One of the way is to modify as below, informing the class that we will use the restore in EntrustUserTrait instead of the one found in SoftDeletes, the restore()
in EntrustUserTrait will be calling SoftDeletes' restore()
anyway
use EntrustUserTrait {
EntrustUserTrait::restore insteadof SoftDeletes;
}
@omegachien Thank you for the hint, this helped me with the conflict issue and now soft deletion works.
My only problem is, that when soft deleting the user the role relationships are deleted by Entrust, so when I restore the user, the roles are gone. Isn't the idea of soft deleting about keeping the related data, so it is their when restoring? Is there any way to keep the relations when soft deleting the user with Entrust?
I found the answer to my problem, it's described here: #306
@omegachien Very Thank!
@omegachien thanks a lot, your fix works in Laravel 5.2 also
@omegachien thanks you !good solution
@josejlpp @jcxnet @tranxuandien Not too long ago, GitHub introduced reaction emojis. Please, just thumbs up. Over 20 people get an unnecessary email when you post something.
Thanks.
What about this issue? I've got this "can" trait conflict with lumen 5.2, dingo api, jwt-auth and entrust. Could it solve with may but like to do it perfect ;)
Beware of using @omegachien solution.
When i use his solution and tried to restore "a" single user. Every deleted user get restore instead.
Running code below restore "all" the deleted user , not just "one" when I use @omegachien solution.
$member = User::withTrashed()->where("id" , 1 )->first();
$member->restore();
I decided to use softdelete restore instead. ( hopefully no future bugs :S )
use EntrustUserTrait;
use SoftDeletes { SoftDeletes::restore insteadof EntrustUserTrait; }