2

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]);
3

1 Answer 1

1

You cannot in an easy way since Laravel is just using PHP's builtin bindValue method: https://www.php.net/manual/en/pdostatement.bindvalue.php

See:

You have to bind the values individually with named/placed parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.