title: Clarification with eager loading/mutators/accessors for laravel
body: <p>I'm making a laravel app for work and I need to load all users with their attached role without any nesting of the roles.  I used this tutorial for roles: <a href="https://medium.com/@ezp127/laravel-5-4-native-user-authentication-role-authorization-3dbae4049c8a" rel="nofollow noreferrer">https://medium.com/@ezp127/laravel-5-4-native-user-authentication-role-authorization-3dbae4049c8a</a> . If I use  <code>public $with = ['roles'];</code> on my User model it returns the entire role object within the user object and I need it to just return role:'role_name';</p>
  
  <pre><code> /**
   * set up eloquent between roles/user
   *
   * @return \Illuminate\Database\Eloquent\Relations\belongsToMany
   */
  public function roles() 
  {
      return $this-&gt;belongsToMany(Role::class);
  }
  </code></pre>
  
  <p>Above is in my User model and below is in my Role model to define the relationships.  </p>
  
  <pre><code> /**
   * provides a many-to-many relationship to User model
   *
   * @return User::class
   */
  public function users()
  {
    return $this-&gt;belongsToMany(User::class);
  }
  </code></pre>
  
  <p>I thought that by adding this to the User model:</p>
  
  <pre><code>protected $appends = ['role_name'];
  
  public function getRoleNameAttribute()
  {
      return $this-&gt;attribute['name'];
  }
  </code></pre>
  
  <p>it would return everything but all it does is create a role_name: 'user_name';  On the model.  So I guess I realize I'm accessing just the Users table and not the Roles table in the DB, but again not really sure what to do.  Any help would be greatly appreciated.  </p>