title: Pass Parameter to Relationship Function or alternative solution
body: <p>i know this question has already been asked but the answers dont work for me </p>
  
  <p>i have a table called <code>channel_posts</code> with this model  </p>
  
  <pre><code>class ChannelPost extends Model
  {
  
      function PostLike( ){
          return $this-&gt;hasMany('App\ChannelPostLike' ,'post_id');
      }
  
  }
  </code></pre>
  
  <p>and there is <code>channel_post_likes</code> table which i store the likes</p>
  
  <pre><code>channel_post_likes : id , post_id , user_id
  </code></pre>
  
  <p>now in my template there's  like icon ..  if user has liked the post i want it to have <code>class="liked"</code></p>
  
  <p>so i can in my controller check if user has liked the post from DB and send it to view ... but there are alot of ajax calls that partially update the template ... for example if a user send a comment for the post im updating the template via ajax response </p>
  
  <pre><code>    function comment_store(Request $request , $id ){
  
           //store in db
  
          echo json_encode(['html'=&gt; view('include.channel-post-comment' , compact('comments' ,'post'))-&gt;render()]);
      }
  </code></pre>
  
  <p>this means i have to check if user ahs already liked the post here as well and inject it to view </p>
  
  <p>i was wondering if i can do this in the template </p>
  
  <p>like i can add this relation to <code>ChannelPost</code> model </p>
  
  <pre><code>    function UserPostLike( $user_id ){
      return $this-&gt;hasOne('App\ChannelPostLike' ,'post_id')-&gt;where('user_id' , $user_id) ;
  }
  </code></pre>
  
  <p>and in the template i can have </p>
  
  <pre><code>&lt;i class="like-icon @if($post-&gt;UserPostLike(Auth::user()-&gt;id)) liked @endif "&gt;&lt;/i&gt;
  </code></pre>
  
  <p>but of course this doesn't work .... so what is my alternative ? should i check this in the controller fopr every call that updated my template ? </p>