title: Display DB Entries in json Array in Controller (Laravel / PHP)
body: <p>I am trying to write an index function in my PlayerController, so my Vue Component is able to create an array with userId, userName, userVote in this form: [{userId:1, userName:Jimmy,userVote:7},{}...]</p>
  
  <p>I have a Players Table and Session Table, because my Player.userSession and Session.sessionId have the same attribute, I am using Laravel's request to fetch this information, create a variable with the other class with Session's ID and get all user who are part of the room.</p>
  
  <p>Everything should be saved &amp;&amp; returned back.</p>
  
  <p>This is my code so far:</p>
  
  <pre><code> public function index(Request $request)
      {
  
  
          $room = $request-&gt;input('sessionId');
  
          $currentPlayers = Player::where('userSession', $room)-&gt;get();
  
          $userId = $currentPlayers-&gt;userId;
          $userName = $currentPlayers-&gt;userName;
          $userVote = $currentPlayers-&gt;userVote;
  
  
          return json_encode([
          'userId' =&gt; $userId,
          'userName' =&gt; $userName,
          'userVote' =&gt; $userVote]);
  
      }
  </code></pre>
  
  <p>But now it says it : "Property [userId] does not exist on this collection instance."</p>
  
  <p><a href="https://pasteboard.co/IyJyUZ0.png" rel="nofollow noreferrer">https://pasteboard.co/IyJyUZ0.png</a>
  <a href="https://pasteboard.co/IyJypj5.png" rel="nofollow noreferrer">https://pasteboard.co/IyJypj5.png</a></p>