Level 60
something like this
DB::select("SELECT * FROM users WHERE user_id NOT IN (:user_list_to_exclude)", [
'user_list_to_exclude' => implode(', ', $user_list_to_exclude)
]);
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
How can I properly bind an array for a raw query's NOT IN / IN?
The following throws an array to string conversion error:
$user_list_to_exclude = [1, 2, 3];
$data = DB::select("SELECT * FROM users WHERE user_id NOT IN :user_list_to_exclude",
['user_list_to_exclude' => $user_list_to_exclude]);
Thanks
Please or to participate in this conversation.