title: How can I hide a relation on an Eloquent model
body: <p>I'm struggling with an Eloquent dummy issue. I have a model User which has a many to many relation with a model Like.</p>
  
  <p>I'm getting my user model by its id with: </p>
  
  <pre><code>$likedUser = User::findorfail($user_id);
  </code></pre>
  
  <p>At some point in the code, I'm doing:</p>
  
  <pre><code>if ($likedUser-&gt;likes-&gt;where(...)-&gt;count()) {
  ...
  }
  </code></pre>
  
  <p>Then, I want to return my $likedUser WITHOUT the likes (added in the IF condition above by Laravel). How can I do that? If I do that, it does not work:</p>
  
  <pre><code> return response()-&gt;json([
        'is_matched' =&gt; $isMatched,
        'liked_user' =&gt; $likedUser,
   ], 200);
  </code></pre>
  
  <p>I would love to have a <code>$likedUser-&gt;without('likes')</code> to remove the relation added by Laravel. I tried to <code>$outputUser = $likedUser-&gt;replicate()</code> but the unique field of my models disappears.. </p>
  
  <p>1) What's the elegant way of only returning my User model without its relationship?</p>
  
  <p>2) Why is Laravel adding the relation even if I never set my variable but only use it in a IF? </p>
  
  <p>Thanks a lot for your time guys!</p>