Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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%';
like image 728
Jeremy Avatar asked Sep 07 '18 21:09

Jeremy


3 Answers

Simply you can use the model to get that result

User::where('username', 'not like', "%ray%")->get();
like image 141
Salar Pourfallah Avatar answered Nov 16 '22 03:11

Salar Pourfallah


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();

like image 39
Jeremy Avatar answered Nov 16 '22 03:11

Jeremy


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();
like image 4
Sunil kumawat Avatar answered Nov 16 '22 03:11

Sunil kumawat