I believe it's not possible to use whereIn with JSON right now. However feel free to shoot in a PR with this functionality.
Documentation: https://laravel.com/docs/5.6/queries#json-where-clauses
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I tried doing this
// Migration
$table->json('map_data')->nullable();
// Map data is
map_data = {
'bands' => ['1', '2'],
}
// Query
$query->whereIn('map_data->bands', ['1']);
I'm getting this error
QLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bands,
Made it work by doing this
$arr = ['1', '2'];
$arr = (string) json_encode($arr);
$arr = "'" . $arr . "'";
$query->whereRaw('JSON_CONTAINS(map_data->"$.band",'. $arr.')');
What's the better to write this?
Please or to participate in this conversation.