I am trying to access specific data in a json column using a laravel controller, the DB column is called ‘figuresinorder’. I want to access the “wants” key but it’s not working when there are multiple values stored.
{“wants”: [“1”], “trades”: [“12,33,234”]} – this works
{“wants”: [“1,2,3”], “trades”: [“12,33,234”]} – does not work
The query in the controller is as follows:
$figures2 = customtrades::whereJsonContains('figuresinorder->wants', ['1'])->get();
Any help will be greatly received, been stuck on this for longer than I dare to admit.
Advertisement
Answer
MySQL & PostgreSQL support whereJsonContains()
with multiple values like this way :
customtrades::whereJsonContains('figuresinorder->wants', ['1','2','3'])->get();
For more, see the documentation here