title: Laravel query and filtering
body: <p>I'm trying to work out the best approach to filtering for this query, I've tried a few different things but can't come up with a solid solution.</p>
  
  <p>Essentially we have the general query which is fine does exactly what it needs to, the problem is I need to be able to filter against user input on an answers table.</p>
  
  <pre><code>$profiles = User::with('photos', 'answers')
          -&gt;where('id', '!=', $user_id)
          -&gt;where('gender', $gender)
          -&gt;where('location', $location)
          -&gt;where('deleted_at', null)
          -&gt;whereNotExists(function($query) use ($user_id)
          {
              $query-&gt;select(DB::raw('user_id1, user_id2'))
                                      -&gt;from('approves')
                                      -&gt;whereRaw("users.id = approves.user_id2 AND approves.user_id1 = '$user_id'");
          })
          -&gt;whereNotExists(function($query) use ($user_id)
          {
              $query-&gt;select(DB::raw('user_id1, user_id2'))
                      -&gt;from('likes')
                      -&gt;whereRaw("users.id = likes.user_id2 AND likes.user_id1 = '$user_id'");
          })
          -&gt;take(15)
          -&gt;get();
  </code></pre>
  
  <p>That uses a couple of user inputs to alter the query, now the user can also filter by a variety of other criteria against a user's profile answers which is where I'm stuck.</p>
  
  <p>The answers table's layout is id, user_id, question_id, answer it had to be like this to allow expansion later on.</p>
  
  <p>Does anyone have any idea how I could filter against this with various other inputs for example if a user was filtering by question_id '1' and answer 'awesome'. Notably there are multiple inputs not just one to compare against and they only need comparing if they've been entered.</p>
  
  <p>Any thoughts or advice is greatly appreciated :)</p>
  
  <p>Edit:</p>
  
  <pre><code>id | user_id | question_id | answer
  1  | 2       | 1           | dad
  2  | 2       | 2           | lion
  3  | 2       | 3           | 5
  </code></pre>