title: Trying to return pivot data in Resource Laravel
body: <p>I am trying to return pivot data to a resource.
  The pivot table works, I can add and remove entrys like expected, but I am not able to get the user_id returned in ActivityResource...
  In the Laravel Documentation it looks so easy, am I missing something?</p>
  
  <pre class="lang-php prettyprint-override"><code>// Activity.php
  class Activity extends Model
  {
      public function members()
      {
          return $this-&gt;belongsToMany('App\User', 'activity_user', 'user_id', 'activity_id')-&gt;withPivot('activity_id','user_id')-&gt;withTimestamps();
      }
  }
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>// User.php
  class User extends Authenticatable
  {
      public function joinedactivities()
      {
          return $this-&gt;belongsToMany('App\Activity');
      }
  }
  </code></pre>
  
  <p>In my ActivityController I want to return a newly created ActivityResource with 'eager-loaded' relationship</p>
  
  <pre class="lang-php prettyprint-override"><code>// ActivityController 
  public function show($id)
  {
      $activity = Activity::with('members')-&gt;findOrFail($id);
  
      /* foreach ($activity-&gt;members as $user) {
          echo $user-&gt;id . " "; // With this I can actually see the right ids
      }
      return;*/
  
      return new ActivityResource($activity);
  }
  </code></pre>
  
  <p>ActivityResource:</p>
  
  <pre><code>public function toArray($request)
  {
      return [
          'id' =&gt; $this-&gt;id,
          'title' =&gt; $this-&gt;title,
          'attendees' =&gt; $this-&gt;whenPivotLoaded('activity_user', function () {
              return $this-&gt;pivot-&gt;user_id;
          }),
      ];
  }
  </code></pre>
  
  <p>I dont get any errors instead the attendees field is just not returned. I tried so many things, struggeling with that. Help very appreciated.
  I am using Laravel 6.</p>