5

I need to do following

Model::select('column')->whereIn('column','!=',array)->first();

So how can i achieve this. Any suggestions Thank you.

Riaz Khan
  • 247
  • 1
  • 3
  • 12
  • 1
    not if you put `,array)` in there (probably a syntax error as array is a keyword in PHP). Well I don't use Laravel, but I can tell that probably wont do what you want. Maybe it's just a typo in the question? – ArtisticPhoenix Mar 07 '19 at 06:52
  • 1
    You can use `whereNotIn('column', $array)`. You can check out docs @ https://laravel.com/docs/5.8/queries#where-clauses – Iftikhar uddin Mar 07 '19 at 07:34

4 Answers4

9

Instead of whereIn you can use whereNotIn.

Like this:

Model::select('column')->whereNotIn('column', array(1,2,3))->first();
Inzamam Idrees
  • 1,955
  • 14
  • 28
4

You are looking for whereNotIn('column', $array). See the Queries documentation for more methods.

FatBoyXPC
  • 861
  • 7
  • 15
4

Use

Model::whereNotIn('id',[10,20])->select('id')->first();

Go through Laravel Eloquent “WHERE NOT IN”

bhavinjr
  • 1,663
  • 13
  • 19
3

try this:

Model::select('column')->whereNotIn('column',array)->first();
PHP Geek
  • 3,949
  • 1
  • 16
  • 32