我的数据库中有一个栏目, 里面存放着一个 json, 我想恢复我 json 的某个对象的价值, 以便对其进行测试
所以我的专栏 "JSON" 包含
{
"type":"index",
"data ":{"index":2}
}
如果我收到 2, 我需要得到这个列, 其中包含索引 2 删除它, 我已经尝试了这:
$column = Table::where('JSON["data"]["index"]','=', '2' )
->first();
Table::dropColumn($column);
但它不工作, 因为我不能得到索引
如果你使用的是最新的拉拉维尔版本, 那么,
$column = Table::where('JSON->data->index','2')->first();
应该管用的
你可以参考官方的拉拉维尔文件的 json 在这里条款。
只需使用类似的 SQL
->where('JSON', 'like', '%"index": "2"%');
Since you gave JSON value as a string, it was unable to get the index value.
Can you please try like below,
$column = Table::whereRaw(JSON["data"]["index"], '=', '2' )
->first();
Table::dropColumn($column);