I am trying to search sql data from raw that hold json data. I am trying to search query by using REGEX but its not working and I also want to know is there is a smart way to do that please tell me.
"Riyaz" is value I want - exact value to make sure it search only that keyword.
$customerlist=Customer::where("group", "REGEXP", '^Riyaz$')
->orderBy('id', 'DESC')
->get();
// DB JSON = {"name":["Riyaz","Saifi"]}
You should use the whereJsonContains
query operator to perform a search on a JSON object:
$customersList = Customer::whereJsonContains('group->name', 'Riyaz')
->orderBy('id', 'DESC')
->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.