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?
CodePudding user response:
Use https://laravel.com/docs/8.x/queries#json-where-clauses
$pharmacies = Pharmacy::whereJsonContains('area', 10)
->pluck('id);
