0

I have an array $blshopids = [5,8]; that I want to insert into a raw SQL statement:

$blshopids = [5,8];
$blshops = implode(",", $blshopids);
$product = 1;

...
where p1.product_id = :product
and p1.shop_id not in (:blshops)
..., ['product' => $product, 'blshops' = $blshops];

As you guess $blshops becomes a string '5,8' and I get p1.shop_id not in ('5,8') instead of p1.shop_id not in (5,8). Any idea how to solve it?

Svetoslav Dimitrov
  • 869
  • 4
  • 16
  • 38
  • please show us the entire php code you are using to build your query. – Jerodev Feb 14 '17 at 20:28
  • Let me rephrase the question. How to turn array into comma separated integers? Query doesn't really matter. – Svetoslav Dimitrov Feb 14 '17 at 20:32
  • Check whereNotIn on [documentation](https://laravel.com/docs/5.4/queries#where-clauses). Also check (https://laravel.com/docs/5.4/queries#raw-expressions) – jetblack Feb 14 '17 at 20:33
  • 1
    Possible duplicate of [Can I bind an array to an IN() condition?](http://stackoverflow.com/questions/920353/can-i-bind-an-array-to-an-in-condition) – user1669496 Feb 14 '17 at 21:33

0 Answers0