1

Here in my code i have used ZizacoEntrust package for authentication. And following ACL tutorial step by step When i`m trying to run code, in browser it shows error like in picture

Error Message: "Trait method roles has not been applied, because there are collisions with other trait methods on App\User"

    <?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
use Laravel\Passport\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
    use EntrustUserTrait;
    use HasRoles;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

I don`t know what exactly happening here. In tutorial used - Spatie, for some moments i used to use zizaco. nothing additional.

Mike
  • 852
  • 9
  • 17
Khamid
  • 11
  • 1
  • 2
  • One of the other traits you are using in this class is using the same method names. Specifically the `roles` method – Mike Jan 25 '19 at 09:11
  • 1
    Traits add functions to a class. Function names need to be unique within a class. If 2 Traits add a function with the same name, you will get this result. This is a comment because I do not provide a solution for your specific problem, only insight. – online Thomas Jan 25 '19 at 09:11
  • 1
    Please share the whole error message in text form, not in images – Nico Haase Jan 25 '19 at 09:22
  • Possible duplicate of [Collisions with other trait methods](https://stackoverflow.com/questions/25064470/collisions-with-other-trait-methods) – Nico Haase Jan 25 '19 at 09:23

2 Answers2

0

You can rename that method like so:

class User {
    use YourTrait {
        roles as protected traitRoles;
    }
}
-1

In case anyone is stumbling upon this issue in 2022, as I have, I received the same error but the case was that I had accidentally duplicated the use MyTrait statement. The solution was to remove the duplicated use statement. However, this didn't cause any issues in terms of breaking the code.

James Stewart
  • 869
  • 12
  • 33