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
Post a Comment