【发布时间】:2021-08-17 19:25:57
【问题描述】:
我有一个表,其 has 列包含一个 json 字段和 postgresql 作为包含此示例的数据库存储:
{"wants_newsletter": "true", "favorite_color": "red"}
如果我像这样在 laravel 上查询:
$model = Model::where('column->favorite_color', 'red')->first();
我可以成功获取该行,现在可以这样做
$id = $model->id;
但是当在同一列有这种json结构
{"wants_newsletter": ["true"], "favorite_color": ["red","blue"]}
如果我像这样在 laravel 上查询:
$model = Model::where('column->favorite_color[0]', 'red')->first();
我得到$model 为空,这意味着我没有获取一行。
在laravel中怎么做?
我在搜索时找到的资源是: How can I make query where json column in the laravel? https://mattstauffer.com/blog/new-json-column-where-and-update-syntax-in-laravel-5-3/
【问题讨论】:
标签: php laravel postgresql