Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

engrlaravel's avatar

Laravel eloquent Query problem

My eloquent query generates below sql query

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

Query is here

$tasks = Task::where('deleted_at', null)->where('company_id',$company_id);
 $tasks = $tasks->where('created_by',$user_id);
 $tasks = $tasks->orWhereIn('id',$task_ids);

Now there is status fields in tasks table which has either 0 or 2 values. I want only to select status=2, BUT when i user

$tasks = $tasks->where('status',0)

It give me wrong result. the real data is TOTAL Records=30, Status=2 records = 9, Status=1 records are 21.

where is the problem in my query

0 likes
2 replies
bobbybouwmann's avatar

That depends on the column type! If this is a string type column the where('status', 0) might not work properly. If this is an integer type column, this should work fine.

Does $tasks = $tasks->where('status', 2) work for you?

Please or to participate in this conversation.