I want to write this query in eloquent using raw queries :
INSERT INTO table SELECT * FROM other_table WHERE other_table_id IN (1,2,3)
I've tried writing it like this :
use Illuminate\Database\Capsule\Manager as DB;
$insert_db = DB::select("SELECT products_id FROM products WHERE products_id IN (?)", [[265792,265787,265743]])
But this is giving me an empty array as a result.
What is the correct way of writing this using the capsule manager? (I absolutely need to do it using DB::select
)
This question is asking the same thing, back in 2013. Back then it was not possible. So did that change today? Can we use WHERE IN (?)
in the latest versions of eloquent? Knowing that I NEED to use ?
for security, and not concatenate the string or it would be meaningless to use PDO at all.
EDIT :
The question is more about dynamic values. I can't use :
DB::select("SELECT products_id FROM products WHERE products_id IN (?, ?, ?)", [265792,265787,265743]);
Because the array [265792,265787,265743]
is being built elsewhere. So imagine the following code
foreach($test as $k => $v) {
$arr[] = $v['something']
}
DB::select("SELECT products_id FROM products WHERE products_id IN (?)", [[$arr]]);