title: Access column of target table after calling relationship - Laravel
body: <p>I have three tables as follows</p>
  
  <p>Base Table</p>
  
  <pre><code>users
      id - integer
      name - string
  </code></pre>
  
  <p>Target Table</p>
  
  <pre><code>roles
      id - integer
      name - string
  </code></pre>
  
  <p>Pivot Table</p>
  
  <pre><code>role_user
      user_id - integer
      role_id - integer
  </code></pre>
  
  <p>Many to many relationship is exist between <code>users</code> and <code>roles</code> table</p>
  
  <p>If I want all the users with role_id of '1' so I can simply do this as</p>
  
  <pre><code>$result = User::whereHas('roles', function ($q){
     $q-&gt;where('roles.id', 1);
  });
  </code></pre>
  
  <p>but I also want the role name correspond to role_id '1' which is <code>name</code> column of <code>roles</code> table.</p>
  
  <p>Is there any way I can append role name into <code>$result</code> collection.</p>