我有一个表“通知”。在我的数据列中,我有一个类似数组的:
{
"title":"Something",
"arr":{
"id":12,
"name":"HelloWorld",
"avatar":null
}
}
我想检查元素(通知)例如 arr->id == 12
(或其他内容)。
我尝试 make query buildng 但没有任何效果。示例:
$hello = auth()->user()->unreadNotifications->where('notifiable_id', Auth::user()->id)
->where('data', '%12%')->first();
或
$hello = auth()->user()->unreadNotifications->where('notifiable_id', Auth::user()->id)
->where('data->arr->id', '12')->first();
谁知道怎么做?
最佳答案
您可以使用此 ..SELECT JSON_SEARCH(......) 获取更多引用,您可以引用此链接 How to search JSON array in MySQL?
关于mysql - 从 MySQL 的列中查找数组中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57471860/