Laravel Eloquent - 如何查询 NOT LIKE?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52229588/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:02:02  来源:igfitidea点击:

Laravel Eloquent - How to query NOT LIKE?

laraveleloquent

提问by Jeremy Quick

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

我怎么能找到不像某个字符串的东西。

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

回答by Salar Pourfallah

Simply you can use the model to get that result

只需使用该模型即可获得该结果

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

回答by Jeremy Quick

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:

根据您的需要,有几种不同的选择。您可以使用以下任何一项来查找与某个字符串不同的内容:

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

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

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

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

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

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

回答by Sunil kumawat

Use DB facade

使用 DB 门面

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

Also you can use

你也可以使用

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