data
这是表列中的 JSON 值things
:
{a: [{b: 1}, {b: 2}]}
我可以使用这样的原始查询获取所有things
包含b
等于 1 的 a :
select * from things where data @> '{ "a": [{"b": 1}] }';
我知道我们可以使用 Laravel 使用带有 JSON where 子句的 Laravel 运行查询:https ://laravel.com/docs/5.4/queries#json-where-clauses 。我可以写如下内容:
Thing::where('a->c', 'foobar');
但是我可以用 Laravel 的 Query Builder 写一个 where 来检查是否a
包含{b: 1}
就像在原始查询中一样吗?