Reputation: 2180
I have a table that has a column named version that has four rows containing values
|Version |
|--------|
|5.3 |
|5.2 |
|5.3 |
|5.2,5.3 |
I want to get rows that's values are not like 5.2
I mean, I want to get the first and third rows not second and fourth rows.
I used Eloquent Model 'Menu' to make the query as below.
$query = Menu:where('version', 'NOTLIKE', '%5.2%')->get();
$numberRows = count($query);
$numberRows
equals to 0
.
Am I in the right way? Or, is there any other way to do this? I need help.
Upvotes: 10
Views: 23092
Reputation: 614
you need to give a space between NOT and LIKE, so it will look like this
$query = Menu:where('version', 'NOT LIKE', '%5.2%')->get();
Upvotes: 0
Reputation: 11
$query->where('field', Auth::user()->id)
->orWhere('field','NOT LIKE', '%,'.Auth::user()->id.',%')
->orWhere('field','NOT LIKE', '%'.Auth::user()->id.',%')
->orWhere('field','NOT LIKE', '%,'.Auth::user()->id.'%');
})
Upvotes: 0
Reputation: 614
you need to add a space in between NOT LIKE so it will look like this
$query = Menu:where('version', 'NOT LIKE', '%5.2%')->get();
$numberRows = count($query);
Upvotes: 1
Reputation: 4114
Change NOTLIKE to NOT LIKE
Correct code:
$query = Menu::where('version', 'NOT LIKE', '%5.2%')->get();
$numberRows = count($query);
Upvotes: 26
Reputation: 661
Your error is this 'NOTLIKE'
resolve this 'NOT LIKE'
try this:
$query = Menu::where('field', 'NOT LIKE', '%5')->get();
$query = Menu::where('field', 'NOT LIKE', '5%')->get();
$query = Menu::where('field', 'NOT LIKE', '%5%')->get();
Upvotes: 1
Reputation: 447
By the way you need a double colon ::
.
Your code should then be
$query = Menu::where('version', 'NOT LIKE', '%5.2%')->get();
$numberRows = count($query);
Upvotes: 5
Reputation:
You are missing a space between not like clause.
https://laravel.com/docs/5.3/queries#where-clauses
Upvotes: 3