swapnil mane
swapnil mane

Reputation: 257

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

I have used multi-select in laravel search. 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);

Upvotes: 1

Views: 1016

Answers (1)

swapnil mane
swapnil mane

Reputation: 257

I was passing an arary inside an array and istead of where i wrote 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);

Upvotes: 1

Related Questions