I am having trouble querying a json column.
Previously my code was
$query->whereIn(\'user\', $users);
Now i have changed the db type
If $users
is array of names then you should iterate over it and add orWhereRaw
condition, note that orWhereRaw can accept an array of parameter:
$users = ["Tom", "Bob"];
foreach( $users as $user) {
$leads->orWhereRaw("JSON_CONTAINS(user, ?)", [$user]);
}
$leads = $leads->get();
MySQL expects a JSON string:
$leads->whereRaw('JSON_CONTAINS(user, ?)', [json_encode($users)])
In Laravel 5.6.24 you can use whereJsonContains()
:
$leads->whereJsonContains('user', $users)