[英]Laravel 5.8 Model whereJsonContains returning only exact matches
Laravel: 5.8 Laravel:5.8
I'm currently having some issues with my whereJsonContains
query.我的whereJsonContains
查询目前存在一些问题。 I'm trying to search an object and if the string is an exact match or partial match I get results, at the moment I am only getting exact matches.我正在尝试搜索 object,如果字符串是完全匹配或部分匹配,我会得到结果,目前我只能得到完全匹配。
$quote->whereJsonContains( 'quotes->current' , [ 'quote' => $request->input( 'quote' ) ] );
I've removed the unnecessary code as this is part of a search filter.我删除了不必要的代码,因为这是搜索过滤器的一部分。 The rest is working perfectly, but I can't seem to find anything in the docs about this or any working examples. rest 运行良好,但我似乎在文档中找不到任何关于此或任何工作示例的内容。
Example of json object in DB: DB中的json object示例:
{
"current": [
{
"quote": "This is a test quote 1",
"page": "7",
"who": "Nancy Harris",
"explanation": "This is a text explanation about quote 1",
"tags": "test1, testing, test",
"created": "2019-10-30T00:38:20.414818Z",
"updated": "2019-10-30T00:38:20.414826Z"
},
{
"quote": "This is a test quote 2",
"page": "60",
"who": "Agnes Bates",
"explanation": "This is a text explanation about quote 2",
"tags": "test1, testing, test",
"created": "2019-10-30T00:38:20.414818Z",
"updated": "2019-10-30T00:38:20.414826Z"
},
{
"quote": "This is a test quote 3",
"page": "11",
"who": "Wayne Griffin",
"explanation": "This is a text explanation about quote 3",
"tags": "test1, testing, test",
"created": "2019-10-30T00:38:20.414818Z",
"updated": "2019-10-30T00:38:20.414826Z"
}
]
}
Try to extend to your qoute data.尝试扩展到您的 qoute 数据。
$quote->whereJsonContains( 'quotes->current->qoute' ,'like', request('quote'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.