title: Eloquent: Api Resource - Can't retrieve an information from pivot table
body: <p><br>
  I'm currently using <code>Laravel 5.6</code>, i want to create an user access control. I'm using three table : <code>user (id, username, email, password)</code>, <code>role (id, role, desc)</code> and a pivot table <code>role_user (user_id, role_id)</code>. My code is like below :<br></p>
  
  <p>User Model</p>
  
  <pre><code>public function roles() {
      return $this-&gt;belongsToMany(Role::class);
  }
  </code></pre>
  
  <p>Role Model :</p>
  
  <pre><code>/**
  * Role Model
  */
  public function users() {
      return $this-&gt;belongsToMany(User::class);
  }
  </code></pre>
  
  <p>Api Resource :</p>
  
  <pre><code>/**
  * Api Resource
  */
  public function toArray($request)
  {
     return [
        'id' =&gt; $this-&gt;id,
        'username' =&gt; $this-&gt;username,
        'email' =&gt; $this-&gt;email,
        'role' =&gt; $this-&gt;whenPivotLoaded('role_user', function (){
            return $this-&gt;roles-&gt;name;
        })
        ];
     }
  </code></pre>
  
  <p>The problem is when i want to access the role information from pivot table, the role is dissappear and i got blank role information like this : <br></p>
  
  <pre><code>{
      "data": {
          "id": 1,
          "username": "john",
          "email": "john.doe@mail.com",
      }
  }
  </code></pre>
  
  <p>Could anyone here to help me to solve this problem?
  <br><strong>Thank You ~</strong></p>