Laravel 5.3 查询构建器:“NOTLIKE”不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40967229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.3 query builder: 'NOTLIKE' not working
提问by Md. Harun Or Rashid
I have a table that has a column named version that has four rows containing values
我有一个表,其中有一个名为 version 的列,该列有四行包含值
|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.
我想得到那些值不像5.2
我的意思的行,我想得到第一行和第三行而不是第二行和第四行。
I used Eloquent Model 'Menu' to make the query as below.
我使用 Eloquent 模型“菜单”来进行如下查询。
$query = Menu:where('version', 'NOTLIKE', '%5.2%')->get();
$numberRows = count($query);
$numberRows
equals to 0
.
$numberRows
等于0
。
Am I in the right way? Or, is there any other way to do this? I need help.
我的方式正确吗?或者,有没有其他方法可以做到这一点?我需要帮助。
回答by Parth Vora
Change NOTLIKE to NOT LIKE
将不喜欢改为不喜欢
Correct code:
正确代码:
$query = Menu::where('version', 'NOT LIKE', '%5.2%')->get();
$numberRows = count($query);
回答by Aaron F
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);
回答by Aaron F
You are missing a space between not like clause.
您在 not like 子句之间缺少空格。
回答by C47
Your error is this 'NOTLIKE'
resolve this 'NOT LIKE'
你的错误是'NOTLIKE'
解决这个问题'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();
回答by Jasbin Karki
you need to add a space in between NOT LIKE so it will look like this
你需要在 NOT LIKE 之间添加一个空格,所以它看起来像这样
$query = Menu:where('version', 'NOT LIKE', '%5.2%')->get();
$numberRows = count($query);
回答by Vikas Kumar
$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.'%');
})