【发布时间】:2019-07-27 13:10:28
【问题描述】:
我的数据以 JSON 数组的形式存储在 from 列中,如下所示:
[{"emailAddress": {"name": "Test", "address": "example@example.com"}}]
我想在该列中“不区分大小写”搜索。这是我迄今为止尝试过的(没有成功):
->orWhereRaw('lower(from->"$[*].emailAddress.name") like lower(?)', ["%{$searchTerm}%"]);
->orWhereRaw('lower(from->"$.emailAddress.name") like lower(?)', ["%{$searchTerm}%"]);
->orWhereRaw('lower(from->emailAddress"$.name") like lower(?)', ["%{$searchTerm}%"]);
都出现同样的错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from->"$[*].emailAddress.name") like lower(?)' at line 1
“区分大小写的查询”
->orWhere('from->emailAddress->name', 'like', "{$searchTerm}");
工作没有任何问题。
我正在使用 MySql 5.7.25 和 Laravel 5.8。
【问题讨论】: