I am using Laravel 6 & mysql 7
I have below query
$tasks = Task::where('deleted_at', null)->where('company_id',$company_id);
$tasks = $tasks->where('created_by',$user_id);
$tasks = $tasks->orWhereIn('id',$task_ids);
It generates below raw query when i print it
SELECT * FROM `tasks` WHERE `deleted_at` IS NULL AND `company_id` = 25 AND `created_by` = 20 OR
`id` IN(112,...215) ORDER BY `id` DESC
Now Id 112 is deleted but still showing in result, although i have where('deleted_at', null) condition but it is not working
I want to apply all other conditions on $task_ids as well
How this can be achieved with optimized query?
UPDATED: Here is complete scenario
I want to select all records which is created by me or assigned to me. Here is my complete code.
$tasks = Task::where('deleted_at', null)->where('company_id',$company_id);
$tasks = $tasks->where('created_by',$user_id);
$task_ids = TaskUser::where('user_id',$user_id)->pluck('task_id')->all();
$tasks = $tasks->orWhereIn('id',$task_ids);
where A and B and C or D, so theid=112record is successfully passed by condition D.condition A (deleted_at is null)put effect oncondition D (where in 112...). u can change your code towhere A and (B and C or D)orwhere (A and B and C) or (A and D)