Laravel 5.8模型,其中Json包含仅返回精确匹配项



Laravel:5.8

我的whereJsonContains查询当前存在一些问题。我试图搜索一个对象,如果字符串是完全匹配或部分匹配,我会得到结果,目前我只得到完全匹配。

$quote->whereJsonContains( 'quotes->current' , [ 'quote' => $request->input( 'quote' ) ] );

我已经删除了不必要的代码,因为这是搜索过滤器的一部分。其余的都很好,但我似乎在文档中找不到任何关于这个或任何工作示例的内容。

数据库中json对象示例:

{
"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"
}
]
}

尝试扩展到您的qute数据。

$quote->whereJsonContains( 'quotes->current->qoute' ,'like', request('quote'));

最新更新