mercredi 17 novembre 2021

How to find a value in JSONB column?

I have a table with a jsonb column(for example:phones) which has [] as a default value. I need to find a note where phones column contains value which I need or ILIKE it. What can I do?

I have tried to take it with where, whereRaw(JSON_CONTAIN), but unfortunately it returns nothing. For example: phones column [907 999 999 09, 950 000 485 99, 934 433 653 76] And I have a dinamic value 485, how I can get the note where phones contain 950 000 485 99

        Cities::query()->whereRaw(
            'JSON_CONTAINS(phones, \'["485"]\')'
        )->get();

OR

where('phones', 'like', "%\"{485}\"%")

These examples do not work



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire