【发布时间】:2021-08-08 07:05:39
【问题描述】:
代码
//text to search
$details = "Successfully";
ActivityLog::with('getCauserDetails')
->when($details ?? false, function ($q) use ($details) {
$q->whereJsonContains('properties->activity', $details);
})
->get()
->toArray();
表结构
id - int
name - varchar
properties - json
user_id - int
Json 数据
{
"ip":"192.168.0.1",
"platform":"Windows",
"activity":"Successfully logout"
}
{
"ip":"192.168.0.1",
"device":"WebKit",
"browser":"Chrome",
"platform":"Windows",
"activity":"Successfully logged in"
}
问题:以上代码已经成功搜索到JSON数据中的数据值,但需要搜索成完整的句子。比如“Successfully logout”,如果我用“Successfully”句搜索,是不会过滤数据的。有谁知道如何使用JsonContains 中的SQL LIKE 运算符 对其进行过滤,这意味着如果我使用句子“Successfully”进行过滤,它也会返回数据而不是完整的句子。
【问题讨论】: