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 abccolumn equals to aor bor 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 whereInfor more compact solution:
或者作为替代,您可以使用whereIn更紧凑的解决方案:
App\SomeModel::whereIn('abc', ['a', 'b', 'c'])->get();
Which checks if the value of the abccolumn is present in the array passed.
它检查abc列的值是否存在于传递的数组中。
You can check out the Laravel documentation for more info on using Where Clauses.
您可以查看 Laravel 文档以获取有关使用Where 子句的更多信息。

