There is no count in that query, so I don't think it's that query that generates the error.
However try changing the ->get() to ->toSQL() and take a look at the generated query
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Dear Friends, In my query in Laravel 10 the below code
$operatorRole = OperatorModel::whereNotIn('id',$newArray)->where('role', $verifierRole)->select('id','operator_code','role')->groupBy('id','operator_code','role')->get();
shows error as
"message": "count(): Argument #1 ($value) must be of type Countable|array, string given",
How to use $newArray with structure
Array ( [0] => 1 [1] => 7 ) change this to ['1','7']. But still got the error .
Please advise
Thanks
Anes P A
Try this
// Convert elements in $newArray to strings and reindex the array
$newArrayStrings = array_values(array_map('strval', $newArray));
// Use $newArrayStrings in the whereNotIn clause
$operatorRole = OperatorModel::whereNotIn('id', $newArrayStrings)
->where('role', $verifierRole)
->select('id', 'operator_code', 'role')
->groupBy('id', 'operator_code', 'role')
->get();
Please or to participate in this conversation.