mercredi 5 décembre 2018

Search in Json column with Laravel

In my emails table, I have a column named To with column-type Json. This is how values are stored:

[{"emailAddress": {"name": "Test", "address": "test@example.com"}}, {"emailAddress": {"name": "Test 2", "address": "test2@example.com"}}]

Now I want a collection of all emails sent to "test@example.com". I tried:

DB::table('emails')->whereJsonContains('to->emailAddress->address', 'test@example.com')->get();

(see https://laravel.com/docs/5.7/queries#json-where-clauses) but I do not get a match. Is there a better way to search using Laravel (Eloquent)?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2zKtOcB
via IFTTT

Aucun commentaire:

Enregistrer un commentaire