Laravel Eloquent "WHERE NOT IN"

Nur Uddin picture Nur Uddin · Sep 15, 2014 · Viewed 254.1k times · Source

I'm having trouble to write query in laravel eloquent ORM.

my query is

SELECT book_name,dt_of_pub,pub_lang,no_page,book_price  
FROM book_mast        
WHERE book_price NOT IN (100,200);

Now I want to convert this query into laravel eloquent.

Answer

Jarek Tkaczyk picture Jarek Tkaczyk · Sep 15, 2014

Query Builder:

DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();

Eloquent:

SomeModel::select(..)->whereNotIn('book_price', [100,200])->get();