Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

EntrustUserTrait conflicts with other trait methods #480

Open Maiti opened 8 years ago

Maiti commented 8 years ago

how to fix FatalErrorException "Trait method restore has not been applied, because there are collisions with other trait methods on ..." in this code:

use Dimsav\Translatable\Translatable;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Zizaco\Entrust\Traits\EntrustUserTrait;

class User extends Model implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword, EntrustUserTrait {
        Authorizable::can insteadof EntrustUserTrait;
        EntrustUserTrait::can as hasPermission;
    }

    use SoftDeletes;
    use Translatable {
        save as TranslatableSave;
    }
}

help me please

and need laravel 5.2 support)

JayHambidge commented 8 years ago

I had the same problem. SoftDeletes restore method is conflicting with EntrustUserTrait restore method. Example solution:

use SoftDeletes, EntrustUserTrait {

        SoftDeletes::restore insteadof EntrustUserTrait;
        EntrustUserTrait::restore insteadof SoftDeletes;

    }

Further info: http://stackoverflow.com/questions/25064470/collisions-with-other-trait-methods

ravloony commented 8 years ago

This works better, but will need checking in case EntrustUserTrait restore method changes:

use SoftDeletes, EntrustUserTrait {

    SoftDeletes::restore as sfRestore;
    EntrustUserTrait::restore as euRestore;

}

public function restore() {
    $this->sfRestore();
    Cache::tags(Config::get('entrust.role_user_table'))->flush();
}
sebastiaanluca commented 8 years ago

Related: https://github.com/Zizaco/entrust/issues/428


@ravloony Shouldn't the restore method call both trait restore methods?

segadora commented 8 years ago

@sebastiaanluca no because both restore methods will call parent::restore()