简体   繁体   中英

laravel search json data

I am using Laravel 5.8 and one of the column named meta contains json data which store data as {"form_id":31}

I want to get all the record that matches this form_id. I did something like this and it is not working

  $formId = request()->id;
   $query->whereRaw('JSON_CONTAINS("meta" ', $formId));

I have to filter from meta column

table structure

id meta
1 {"form_id":31}
2  {"form_id":31}
3 {"form_id":32}

Laravel supports querying JSON column types on databases that provide support for JSON column types like mysql ....

 $query->whereJsonContains('meta->form_id",$formId);

and if you want exact comparison you can use:

$query->where('meta->form_id",$formId);

more info in Laravel 5.8 doc

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