简体   繁体   中英

Search by JSON field not working in Laravel

This is "tags" field as json in products table:

[{"id":1,"name":"Adidas","slug":"adidas"},{"id":2,"name":"Nike","slug":"nike"}]

In Eloquent, I used query:

$query->whereJsonContains('tags->slug', 'adidas');

But no results are returned.

How can I search by tag's slug in products table with Laravel?

You need to use get();

$query->whereJsonContains('tags->slug', 'adidas')->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM