title: Call to undefined method App\User::role() in Laravel
body: <p>I want to create a list of users with their specific role(or roles if multiple roles given)</p>
  
  <p>In my UserController  </p>
  
  <pre><code>use DB;
  use Auth;
  use Storage;
  
  use App\Role;
  use App\HasRoles;
  use App\User;
  use App\Profile;
  
  $users = User::with('roles')-&gt;where('name', 'admin')-&gt;get();
  return view('dashboard.users.index', compact('users')); 
  </code></pre>
  
  <p>but I am having this error</p>
  
  <p><a href="https://i.stack.imgur.com/9eCE0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9eCE0.png" alt="enter image description here"></a></p>
  
  <p>if I <code>dd($users);</code></p>
  
  <p>I can see that the roles are there</p>
  
  <p><a href="https://i.stack.imgur.com/3GYbj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3GYbj.png" alt="enter image description here"></a></p>
  
  <p>How can I solve the issue? thanks!</p>
  
  <p>EDIT: user model</p>
  
  <pre><code>use Illuminate\Notifications\Notifiable;
  use Illuminate\Contracts\Auth\MustVerifyEmail;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  
  class User extends Authenticatable implements MustVerifyEmail
  {
      use Notifiable, HasRoles;
  
      protected $fillable = [
          'name', 'email', 'phone_number', 'avatar', 'password', 'verification_code'
      ];
  
      protected $hidden = [
          'password', 'remember_token',
      ];
  
      protected $casts = [
          'email_verified_at' =&gt; 'datetime',
          'phone_verified_at' =&gt; 'datetime',
      ];
  
      public function profile()
      {
          return $this-&gt;hasOne('App\Profile', 'user_id','id');
      }
  
      public function mailingAdd()
      {
          return $this-&gt;hasOne('App\MailingAddress', 'user_id','id');
      }
  </code></pre>
  
  <p>user/index.php</p>
  
  <pre><code>@foreach($users-&gt;role as $item)
      &lt;tr&gt;
          &lt;td&gt;{{ $loop-&gt;iteration }}&lt;/td&gt;
          &lt;td&gt;&lt;a href="{{ url('/dashboard/users', $item-&gt;id) }}"&gt;{{ $item-&gt;name }}&lt;/a&gt;&lt;/td&gt;
          &lt;td&gt;{{ $item-&gt;email }}&lt;/td&gt;
          &lt;td&gt;{{ $item-&gt;role()-&gt;name }}&lt;/td&gt;
          &lt;td&gt;{{ $item-&gt;phone_number==null ? 'None' : $item-&gt;phone_number  }}&lt;/td&gt;
          &lt;td&gt;
              @if($item-&gt;phone_verfied_at==null)
                  &lt;span class="badge badge-danger"&gt;not yet verified&lt;/span&gt;
              @else
                  &lt;span class="badge badge-success"&gt;verified&lt;/span&gt;
              @endif
          &lt;/td&gt;
      &lt;/tr&gt;
  @endforeach     
  </code></pre>
  
  <p>Changing <code>@foreach($users-&gt;role as $item)</code> into <code>@foreach($user-&gt;roles as $item)</code> gives me "Property [roles] does not exist on this collection instance"</p>
  
  <p>USER TABLE MIGRATION</p>
  
  <p><a href="https://i.stack.imgur.com/IeUee.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IeUee.png" alt="enter image description here"></a></p>
  
  <p>ROLES AND PERMISSION TABLE MIGRATION</p>
  
  <p><a href="https://i.stack.imgur.com/Ita6j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ita6j.png" alt="enter image description here"></a></p>
  
  <p><strong>ANSWER</strong></p>
  
  <p>base from <strong>Simon Morris</strong>'s answer.</p>
  
  <pre><code>@foreach($users as $user)
      {{ $user-&gt;name }}
      @foreach ($user-&gt;roles as $role)
          {{ $role-&gt;name }}
      @endforeach
  @endforeach
  </code></pre>
  
  <p>I removed the relationship I added base from some of my suggestions here. and implement the answer I pasted above.</p>
  
  <p>That code display the user list with their specific user role or roles if the user given multiple roles. </p>
  
  <p>thanks guys for answering! cheers!</p>