2017-05-30 16 views
0

フィールドにLIKEを使用しているときにリクエストをしようとしましたが、エラーが発生しました。
私はEraquent(ORM)でLaravel 5.3を使用しています。PostgreSQLでエラーが発生しました

$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 %) 

誰かが解決策を見つけるために私を助けることができます。

+0

$ dateの例を挙げることができますか? –

+0

「LIKE」の代わりに「ILIKE」を試してみてください –

+0

ILIKEもうまくいきません。 – Pixel

答えて

0

代わりにこれを試してください:

foreach ($hours as $hour) { 
    $chart[$hour]['hour'] = $hour; 
    $chart[$hour]['allowed'] = VisitsAllowed::where('created_at', '=', Carbon::parse($date)->format('Y-m-d'))->count(); 
    $chart[$hour]['denied'] = VisitsDenied::where('created_at', '=', Carbon::parse($date)->format('Y-m-d'))->count(); 
} 
+0

ILIKEで同じエラーが発生しました – Pixel

+0

フォーマットから '%'を削除して横に追加しても、 –

+0

私は同じエラーがありません。% – Pixel

0

ないきれいな解決策が、日が(2017年5月30日と言う)との間にある場合はテスト00:00:00 YYYY-MM-DDおよびYYYY-MMを-dd 23:59:59が動作します。

$chart[$hour]['allowed'] = VisitsAllowed::where('created_at', '>=', Carbon::parse($date)->format('Y-m-d') . ' 00:00:00') 
      ->where('created_at', '<=', Carbon::parse($date)->format('Y-m-d') . ' 23:59:59') 
      ->count(); 

$chart[$hour]['denied'] = VisitsDenied::where('created_at', '>=', Carbon::parse($date)->format('Y-m-d') . ' 00:00:00') 
      ->where('created_at', '<=', Carbon::parse($date)->format('Y-m-d') . ' 23:59:59') 
      ->count(); 
関連する問題