Mat*_*rez 1 postgresql json laravel eloquent
我正在尝试使用 Eloquent 在 JSON 字段中进行搜索,但现在可以工作,搜索结果为 0。
这是针对 Ubuntu 服务器,运行 PostgresSQL、Laravel 5.8 和 Apache 2。
[{
"value": "1",
"label": "numero"
},{
"value": "2016",
"label": "anio"
},{
"value": "Acer",
"label": "especie"
},{
"value": "2",
"label": "cant_plantar"
}]
Run Code Online (Sandbox Code Playgroud)
PlanificacionInfo::select('datos_complementarios')->WhereJsonContains('datos_complementarios', ["value" => "Escamonda 2019"]);
Run Code Online (Sandbox Code Playgroud)
查询返回空
PostgreSQL 要求对象值位于数组内:
PlanificacionInfo::select('datos_complementarios')
->whereJsonContains('datos_complementarios', [["value" => "Escamonda 2019"]]);
Run Code Online (Sandbox Code Playgroud)
使用原始表达式进行不区分大小写的搜索:
PlanificacionInfo::select('datos_complementarios')
->whereJsonContains(
DB::raw('lower("datos_complementarios"::text)'),
[["value" => strtolower("Escamonda 2019")]]
);
Run Code Online (Sandbox Code Playgroud)