title: Dynamic laravel SQL query builder
body: <p>I'm trying to create a dynamic query with laravel whereby if certain conditions are met it will add to my query. Here is what I have attempted so far. Any guidance please? </p>
  
  <pre><code>    $Tasks = Task::leftJoin('task_recipients', 'tasks.task_id', '=', 'task_recipients.recipient_task_id');
  
      if ($filterAssignedToMe !== NULL) {
          $Tasks-&gt;where('task_recipients.recipient_user_id', '=', $user_id);
      }
  
      if ($filterAssignedByMe !== NULL) {
          $Tasks-&gt;where('tasks.created_by', '=', $user_id);
      }
  
      $Tasks-&gt;groupBy('task_id');
      $Tasks-&gt;get();
  </code></pre>