简体   繁体   English

如何对 laravel 8 中单个列上的多个值运行查询

[英]How to run query on multiple values on single column in laravel 8

I have used multi-select in laravel search.我在 laravel 搜索中使用了多选。 I want to search for data on multiple values.我想搜索多个值的数据。 Here is my code这是我的代码

getting an array from the request从请求中获取数组

$req->state

Getting all the data from request从请求中获取所有数据

[
'DELHI','MAHARASHTRA','KARNATAKA',
]
$data = tbl_company::query()
                ->where(
                    "state",
                    [$req->state]
                )->paginate(100);

I was passing an arary inside an array and istead of where i wrote whereIn我在一个数组中传递了一个数组,而不是我写的where whereIn

$data = tbl_company::where(
                    "state",
                    [$req->state] //passing array inside an array
                )->paginate(100);

Answer回答

$data = tbl_company::query()
                ->whereIn(
                    "state",
                    $req->state
                )->paginate(100);

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

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