在Laravel的whereIn中搜索json值? [英] Search json value in whereIn in laravel?

查看:575
本文介绍了在Laravel的whereIn中搜索json值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$exams=[{"id":1}];

$toReturn['exams'] =exams_list::whereIn('examClasses',$exams)->get()->toArray();

该怎么做?

推荐答案

您可以执行以下操作

$exam_id = 1;
$toReturn['exams'] =exams_list::where('examClasses->"$.id"',$exam_id)->get()->toArray();

//As per your question
//$exams=[{"id":1}]; =======> Wrong way
$exams=["id" => 1];
$toReturn['exams'] =exams_list::where('examClasses->"$.id"',$exam["id"])->get()->toArray();

请参见下面的示例,请参考 https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html

See example given below, Refer https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html

  • 列->路径
  • column->path

在MySQL 5.7.9及更高版本中,->运算符与两个参数一起使用时用作JSON_EXTRACT()函数的别名,两个参数在左侧是列标识符,在右侧是根据JSON求值的JSON路径文档(列值).您可以使用此类表达式代替SQL语句中出现的列标识符.

In MySQL 5.7.9 and later, the -> operator serves as an alias for the JSON_EXTRACT() function when used with two arguments, a column identifier on the left and a JSON path on the right that is evaluated against the JSON document (the column value). You can use such expressions in place of column identifiers wherever they occur in SQL statements.

这篇关于在Laravel的whereIn中搜索json值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆