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();
1条答案
按热度按时间7vux5j2d1#
使用原始表达式强制转换比较值: