2

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?

1 Answer 1

2

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

$pharmacies  = Pharmacy::whereJsonContains('area', 10)
                ->pluck('id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.