title: How can I get exact user plus the user's exact posts in laravel from jwt token laravel
body: <p>I'm trying to get a list of a single user plus his/her post in another table, while passing the user jwt token in the header.</p>
  
  <pre><code>public function getAuthenticatedUser()
  {
      try {
  
          if (! $user = JWTAuth::parseToken()-&gt;authenticate()) {
              return response()-&gt;json(['user_not_found'], 404);
          }
  
      } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
  
          return response()-&gt;json(['token_expired'], $e-&gt;getStatusCode());
  
      } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
  
          return response()-&gt;json(['token_invalid'], $e-&gt;getStatusCode());
  
      } catch (Tymon\JWTAuth\Exceptions\JWTException $e) {
  
          return response()-&gt;json(['token_absent'], $e-&gt;getStatusCode());
  
      }
  
      // the token is valid and we have found the user via the sub claim
  
      $user = auth()-&gt;user();
      $userid = User::where('id', $user-&gt;id);
      $return = UserResource::collection($userid);   
      return response()-&gt;json($return);
  
  
  }
  </code></pre>
  
  <p>While doing it this way I get </p>
  
  <pre><code>BadMethodCallException: Call to undefined method Illuminate\Database\Eloquent\Builder::mapInto() in file C:\xampp\htdocs\doc\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php on line 50
  
  #0 C:\xampp\htdocs\doc\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php(36): Illuminate\Database\Eloquent\Builder::throwBadMethodCallException('mapInto')
  </code></pre>
  
  <p>But if I do it this way;</p>
  
  <pre><code>$user = auth()-&gt;user();
  $userid = User::find($user);
  $return = UserResource::collection($userid);   
  return response()-&gt;json($return);
  </code></pre>
  
  <p>I get a response, but I get two users returned, instead of the exact user with the jwt token</p>
  
  <p>When I return just <strong>auth()->user()</strong> I get the exact user of the jwt but without the post resource.</p>
  
  <p>How can I get exact user plus the user's exact posts</p>