简体   繁体   English

Laravel 查询 - whereIn 或 Where 组合

[英]Laravel query - whereIn orWhere combined

I have a collection Products and我有一个集合Products

productVendors: ["ASICS TIGER","FLEX FIT"] productVendors: ["ASICS TIGER","FLEX FIT"]

productTypes: ["SHOES","T-SHIRTS"]产品类型: ["SHOES","T-SHIRTS"]

productTags: ["autumn","cap"]产品标签: ["autumn","cap"]

I can easily write:我可以很容易地写:

$products->whereIn('productVendors', ["ASICS TIGER","FLEX FIT"])
         ->whereIn('productTypes', ["SHOES","T-SHIRTS"])
         ->whereIn('productTags', ["autumn","cap"])->get();

but thats not what I need.但这不是我需要的。

I need to get all products but like this ->whereIn('productVendors', ["ASICS TIGER","FLEX FIT"]) OR ->whereIn('productTypes', ["SHOES","T-SHIRTS"]) OR ->whereIn('productTags', ["autumn","cap"])->get();我需要获得所有产品,但像这样->whereIn('productVendors', ["ASICS TIGER","FLEX FIT"]) OR ->whereIn('productTypes', ["SHOES","T-SHIRTS"]) OR ->whereIn('productTags', ["autumn","cap"])->get();

It Will be perfect if Laravel has query orWhereIn but don't:(如果 Laravel 有查询orWhereIn但没有:(

How I can build a query like that?我怎样才能建立这样的查询?

Laravel have orWhereIn , I dont konw why you think it doesn't have Laravel 有orWhereIn ,我不知道你为什么认为它没有

$products->orWhereIn('productVendors', ["ASICS TIGER","FLEX FIT"])
         ->orWhereIn('productTypes', ["SHOES","T-SHIRTS"])
         ->orWhereIn('productTags', ["autumn","cap"])->get();

you can find the doc in whereIn / whereNotIn / orWhereIn / orWhereNotIn section.您可以在whereIn / whereNotIn / orWhereIn / orWhereNotIn部分找到该文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM