Jeremy
Jeremy

Reputation: 3809

Laravel Eloquent - How to query NOT LIKE?

How might I find something that is not like a certain string.

SELECT * FROM users WHERE username NOT LIKE '%ray%';

Upvotes: 54

Views: 77123

Answers (3)

Jeremy
Jeremy

Reputation: 3809

There are a few different options depending on your needs. You can use any of the following to find something that is not like a certain string:

Users::where('username', 'not like', "%ray%")->get();

DB::table('users')->where('username', 'not like', '%ray%');

Capsule::table('users')->select('*')->where('username', 'not like', '%ray%')->get();

Upvotes: 9

Sunil kumawat
Sunil kumawat

Reputation: 804

Use DB facade

   $data = DB::table('users')->select('*')->where('username', 'not like', '%ray%')->get();

Also you can use

 $data = User::where('username', 'not like', "%ray%")->get();

Upvotes: 4

Salar Pourfallah
Salar Pourfallah

Reputation: 1582

Simply you can use the model to get that result

User::where('username', 'not like', "%ray%")->get();

Upvotes: 135

Related Questions