Php laravel:JSON字段与数组的比较

Php laravel:JSON字段与数组的比较,php,mysql,laravel,laravel-query-builder,Php,Mysql,Laravel,Laravel Query Builder,在我的数据库中,我有一个json格式字段,如下所示: 字段名称:功能: laravel-5.7/mysql 同样在它的模型中,我写了这个 [ {"id": 1, "url": null, "name": "A"}, {"id": 2, "url": null, "name": "B"} ] 现在我创建一个数组: protected $casts = [ 'features' => 'array' ]; 如何将$features数组与数据库中的feat

在我的数据库中,我有一个json格式字段,如下所示:

字段名称:功能

laravel-5.7/mysql
同样在它的模型中,我写了这个

[
    {"id": 1, "url": null, "name": "A"}, 
    {"id": 2, "url": null, "name": "B"}
]
现在我创建一个数组:

  protected $casts = [
    'features' => 'array'
  ];
如何将
$features数组
与数据库中的
features字段
进行比较

ّ我检查了这些:

$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;


使用原始表达式强制转换比较值:

$fff = \App\Cart::whereFeatures(json_encode($features,JSON_UNESCAPED_UNICODE))->get()->first();

我认为在调用
get()
之前,您正在使用查询生成器,因此它可能会与数据库列中的内容进行字符串比较。
$fff = \App\Cart::whereFeatures(json_encode($features))->get()->first();
$fff = \App\Cart::whereFeatures(json_encode($features,JSON_UNESCAPED_UNICODE))->get()->first();
$fff = \App\Cart::whereRaw('features = cast(? as json)', json_encode($features))->get();