title: Undefined property: Illuminate\Database\Query\Builder::$sessionId
body: <p>This is my PlayerController, Player &amp; Session Model and Resource.</p>
  
  <p>I want to use the input (sessionId from SessionsTable) to fetch user from the room with the same id (userSession) and return an array in this format: [{userId:1, userName: stacki, userVote:8},{...},...]</p>
  
  <p>I already asked [here][1] to achieve this and now im stuck with this error.
  What do I have to change in order to solve this issue? Simply adding ->first() does not solve my issue, I need more than one record.</p>
  
  <pre><code>
  namespace App\Http\Controllers;
  
  use App\Player;
  
  use Illuminate\Http\Request;
  use App\Http\Resources\Players as PlayerResource;
  
  class PlayerController extends Controller
  {
      public function index(Request $request)
      {
  
          $room = $request-&gt;input('sessionId');
  
          $currentPlayers = Player::where('userSession', $room)-&gt;get();
  
          return PlayerResource::collection($currentPlayers);
  
      }
  
  
  
  
      public function create()
      { }
  
  
      public function update()
      { }
  }
  
  &lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Player extends Model
  {
      protected $fillable = [];
  
      public $sortable = [
          'userId',
          'userName',
          'userVote'
      ];
  
      public function sessions()
      {
          return $this-&gt;hasMany('App\Session');
      }
  
      public function players(){
          return $this-&gt;belongsToMany('App\Session');
      }
  
  }
  
  &lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Session extends Model
  {
      protected $fillable = [];
  
      public function user(){
          return $this-&gt;belongsToMany('App\Player');
  
      }
      public function creator()
      {
          return $this-&gt;hasOne('App\Player', 'userId');
      }
  }
  
  class Players extends ResourceCollection
  {
      /**
       * Transform the resource collection into an array.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return array
       */
      public function toArray($request)
      {
          return [
              'userId' =&gt; $this-&gt;sessionId,
              'userName' =&gt; $this-&gt;userName,
              'userVote' =&gt; $this-&gt;userVote
          ];
      }
  }
  
  `
  
  
    [1]: https://stackoverflow.com/questions/58062014/display-db-entries-in-json-array-in-controller-laravel-php
  </code></pre>