Laravel:5.8
我的whereJsonContains
查询当前存在一些问题。我正在尝试搜索一个对象,如果字符串是完全匹配或部分匹配,我会得到结果,此刻我只能得到完全匹配。
$quote->whereJsonContains( 'quotes->current' , [ 'quote' => $request->input( 'quote' ) ] );
我已删除了不必要的代码,因为这是搜索过滤器的一部分。其余的都运行良好,但是我似乎在文档中找不到关于此或任何可用示例的任何信息。
DB中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"
}
]
}
答案 0 :(得分:0)
尝试扩展到您的qoute数据。
$quote->whereJsonContains( 'quotes->current->qoute' ,'like', request('quote'));