afsara_ben
afsara_ben

Reputation: 672

Laravel model: query from multiple array

I have a db table Pharmacy which has a column area, which is an array.

so for pharmacy id=1 lets say area = [10,12]
for pharmacy id=2 say area = [1,2]
for pharmacy id=3 say area = [1,10]

I want to make an eloquent query which will search through all the data rows of pharmacy table and return only those pharmacy id which has area=10

In return I should get id = [1,3]

How do I do this using eloquent query?

Upvotes: 2

Views: 302

Answers (1)

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

Use https://laravel.com/docs/8.x/queries#json-where-clauses

$pharmacies  = Pharmacy::whereJsonContains('area', 10)
                ->pluck('id);

Upvotes: 2

Related Questions