vendredi 18 août 2017

Laravel 5.4 whereNotIn apparently not working

I have logic in a controller that builds an array called $exclude.

Using dd for $exclude I get :

array:4 [▼
  0 => 2
  1 => 3
  2 => 4
  3 => 5
]

which is correct.

I want to exclude those from a result so I have:

$potype = DB::table('potypes')
                ->whereNotIn('id',[$exclude])
                ->get();

but when I run the query those items are included with the exception of the first in the array. So I enabled the query log with

DB::enableQueryLog();

and ran

dd(DB::getQueryLog());

with the result of

array:1 [▼
  0 => array:3 [▼
    "query" => "select * from `potypes` where `id` not in (?)"
    "bindings" => array:4 [▼
      0 => 2
      1 => 3
      2 => 4
      3 => 5
    ]
    "time" => 0.67
  ]
]

The table has 8 records but running the query is returning 7, only ommiting the first of the list:

Collection {#621 ▼
  #items: array:7 [▼

If I use implode

$ex = implode(',',$exclude) and change the query to ->whereNotIn('id',[$ex]) I get the same result - 7 items with just the first in the list being ignored.

Is this an Eloquent bug or me?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xafx5t
via IFTTT

Aucun commentaire:

Enregistrer un commentaire