title: Laravel query as well as check for boolean at the same time in same query
body: <p>I have four Models: User, Question, Answer and Upvote. Models satisfy the following constraints: </p>
  
  <ul>
  <li><strong>User</strong> can ask <strong>many questions</strong>. </li>
  <li>A <strong>question</strong> has many <strong>answers</strong></li>
  <li>An <strong>answer</strong> belongs to a single <strong>question</strong></li>
  <li>An <strong>answer</strong> have many <strong>upvotes</strong> and downvotes as well</li>
  </ul>
  
  <p><strong>(just like a simple question answer site)</strong></p>
  
  <p>Here is the query I have written:</p>
  
  <pre><code>DB::table('questions')
      -&gt;join('answers', 'answers.question_id', '=', 'questions.id')
      -&gt;join('users', 'users.id', '=', 'answers.user_id')
      -&gt;select('answers.answer_content as answer_content',
               'answers.created_at as created_at',
               'users.name as name',
               'users.id as u_id',
               'users.user_slug as user_slug'
             )
      -&gt;orderBy('answers.created_at', 'desc')
      -&gt;get();
  </code></pre>
  
  <p>Upvotes table contains the columns:</p>
  
  <pre><code>user_id, answer_id, upvote(booolean 1 or 0) 
  </code></pre>
  
  <ul>
  <li>1 - upvoted</li>
  <li>2 - downvoted</li>
  </ul>
  
  <p><strong>My Answer model</strong></p>
  
  <pre><code>public function upvote()
  {
      return $this-&gt;hasMany('App\Upvote', 'answer_id')-&gt;where('upvote', 1);
  }
  
  public function downvote()
  {
      return $this-&gt;hasMany('App\Upvote', 'answer_id')-&gt;where('upvote', 0);
  }
  </code></pre>
  
  <p><strong>Upvote model</strong></p>
  
  <pre><code>public function answer()
  {
      return $this-&gt;belongsTo('App\Answer', 'id');
  }
  </code></pre>
  
  <p>And it gives me expected results from <strong>three</strong> tables user, questions and answer.</p>
  
  <p>What I want to add in it is whether current logged in user has upvoted the perticular answer or not with it. (like facebook shows already liked on a post with a color). How that could be achived?</p>
  
  <p>(if no one is logged in then there is nothing to check. if user is logged in then i want to just get one more thing which is true or false with every row after joining )</p>
  
  <p>I dont to know how to add this checking logic whether user has upvoted and then get true or false. </p>