title: How can add additional Attribute in my JSON response with dynamic value in laravel
body: <p>In my app i have a <strong>Posts</strong> and a <strong>Reacts</strong> table both are connected with relationship.</p>
  <p>In App user can react to a post(like or dislike) and for retrieve this i'm using this function :</p>
  <pre><code>public function feed()
  {
      $posts=Post::with('user')
                  -&gt;with('reacts')
                  -&gt;withCount('comments')
                  -&gt;orderBy('created_at', 'DESC')
                  -&gt;get();
      return response()-&gt;json([&quot;posts&quot; =&gt; $posts]);
  }
  </code></pre>
  <p>the response is:</p>
  <p><a href="https://i.stack.imgur.com/2xf9x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2xf9x.png" alt="enter image description here" /></a></p>
  <p>i want to add one more field in Posts Object for <strong>isUserLiked</strong> and if the current authenticated user liked the post then value will be true or false for him something like this:</p>
  <p><a href="https://i.stack.imgur.com/17VNA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/17VNA.png" alt="enter image description here" /></a></p>
  <p>i can add a additional field but how can i set the value dynamically for that</p>
  <p>this is what i am doing in my Post Model:</p>
  <pre><code> protected $appends = ['isUserLiked'];
   public function getIsUserLikedAttribute($id)
   {
      $react=React::where('user_id',auth()-&gt;user()-&gt;id)-&gt;where('post_id',$id)-&gt;exists();
      return $react;
   }
  </code></pre>
  <p>this is returning false because i don't know any way to pass the arguments(Post id).
  is there any better way i can get the desired response? Thanks!</p>