php - Dynamic laravel SQL query builder -


i'm trying create dynamic query laravel whereby if conditions met add query. here have attempted far. guidance please?

    $tasks = task::leftjoin('task_recipients', 'tasks.task_id', '=', 'task_recipients.recipient_task_id');      if ($filterassignedtome !== null) {         $tasks->where('task_recipients.recipient_user_id', '=', $user_id);     }      if ($filterassignedbyme !== null) {         $tasks->where('tasks.created_by', '=', $user_id);     }      $tasks->groupby('task_id');     $tasks->get(); 

here go:

$tasks = task::leftjoin('task_recipients', 'tasks.task_id', '=', 'task_recipients.recipient_task_id');  if ($filterassignedtome !== null) {     $tasks = $tasks->where('task_recipients.recipient_user_id', '=', $user_id); }  if ($filterassignedbyme !== null) {     $tasks = $tasks->where('tasks.created_by', '=', $user_id); }  $tasks = $tasks->groupby('task_id'); $tasks = $tasks->get(); 

does work?


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -