50

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

SELECT * FROM users WHERE username NOT LIKE '%ray%';
user3253002
  • 1,521
  • 3
  • 21
  • 43
Jeremy
  • 3,620
  • 9
  • 43
  • 75

3 Answers3

127

Simply you can use the model to get that result

User::where('username', 'not like', "%ray%")->get();
Salar Pourfallah
  • 1,402
  • 1
  • 9
  • 10
8

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

Jeremy
  • 3,620
  • 9
  • 43
  • 75
4

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();
Sunil kumawat
  • 804
  • 8
  • 14