Laravel - 如何选择列等于 x 或 y 或 z (以及……)的所有位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34912161/
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 - How do I select all where column is equals to x or y or z (and on..)?
提问by Eliya Cohen
I'm working on Laravel framework version 5.1
我正在使用 Laravel 框架 5.1 版
How do I select all of my rows from an eloquent model where his abc
column equals to a
or b
or c
?
如何从一个雄辩的模型中选择所有的行,他的abc
栏等于a
或b
或c
?
Sorry if I haven't explained myself very well.
对不起,如果我没有很好地解释自己。
回答by Bogdan
You just chain the conditions:
您只需链接条件:
App\SomeModel::where('abc', 'a')->orWhere('abc', 'b')->orWhere('abc', 'c')->get();
Or as an alternative you can use whereIn
for more compact solution:
或者作为替代,您可以使用whereIn
更紧凑的解决方案:
App\SomeModel::whereIn('abc', ['a', 'b', 'c'])->get();
Which checks if the value of the abc
column is present in the array passed.
它检查abc
列的值是否存在于传递的数组中。
You can check out the Laravel documentation for more info on using Where Clauses.
您可以查看 Laravel 文档以获取有关使用Where 子句的更多信息。