我正在嘗試提出請求,並且在created_at
字段上使用LIKE
時出現錯誤。
我使用Laravel 5.3和Eloquent(ORM)。PostgreSQL錯誤和Laravel
$date = Carbon::now();
foreach ($hours as $hour) {
$chart[$hour]['hour'] = $hour;
$chart[$hour]['allowed'] = VisitsAllowed::where('created_at', 'LIKE', Carbon::parse($date)->format('Y-m-d %'))->count();
$chart[$hour]['denied'] = VisitsDenied::where('created_at', 'LIKE', Carbon::parse($date)->format('Y-m-d %'))->count();
}
錯誤:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: timestamp without time zone ~~* unknown
LINE 1: ... aggregate from "visits_allowed" where "created_at" LIKE $1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. (SQL: select count(*) as aggregate from "visits_allowed" where "created_at" LIKE 2017-05-30 %)
有人可以幫助我找到一個解決方案。
你可以舉一個例子爲$ date嗎? –
也許嘗試''ILIKE''而不是''LIKE'' –
ILIKE不工作。 – Pixel