laravel-5.7/mysql在我的数据库中,有一个json格式字段,如下所示:
字段名:特性
[
{"id": 1, "url": null, "name": "A"},
{"id": 2, "url": null, "name": "B"}
]同样在它的模型中,我写了以下文章
protected $casts = [
'features' => 'array'
];现在我创建了一个数组:
$features = array();
temp = array();
temp['id'] = 1;
temp['url'] = null;
temp['name'] = A;
$features[] = temp;
temp = array();
temp['id'] = 2;
temp['url'] = null;
temp['name'] = B;
$features[] = temp;如何将$features array与数据库中的features field进行比较?
ّ,我检查了这些:
$fff = \App\Cart::whereFeatures($features)->get()->first();或
$fff = \App\Cart::whereFeatures(json_encode($features))->get()->first();或
$fff = \App\Cart::whereFeatures(json_encode($features,JSON_UNESCAPED_UNICODE))->get()->first();发布于 2018-12-21 00:12:51
使用原始表达式转换比较值:
$fff = \App\Cart::whereRaw('features = cast(? as json)', json_encode($features))->get();https://stackoverflow.com/questions/53877203
复制相似问题