0

私の Place モデルにこの関係がある場合:

public function openhours()
{
  return $this->hasOne('Hours')->select(DB::raw("IF(CURTIME() BETWEEN open_time AND close_time ,'Open','Closed')"));
}

そして私のルートでは:

 $place = Place::with('openhours')->where('id', '=', 5)->get();

私のテーブル:

Table Name : hours
Fields : 
id          int(11)
place_id    int(11)
open_time   time
close_time  time

テーブル レコード:

id: 1
place_id: 5
open_time: 10:00:00
close_time: 17:00:00

それはただ返します:

 openhours:null

このクエリを phpmyadmin で手動で実行すると、正常に動作します。

私は何を間違っていますか?

前もって感謝します。

4

2 に答える 2

2

以下を App:before フィルターに追加すると、実行中のすべてのクエリとバインディングのダンプが取得されます。

DB::listen(function($sql, $bindings, $time)
{
    var_dump($sql);
    var_dump($bindings);
});

答えではありませんが、雄弁なリクエストが自分の SQL とどのように比較されるかを理解するのに役立つかもしれません。

于 2013-09-22T10:47:58.140 に答える
1

もっと好きなものは必要ありませんか;

Place::find($id)->openhours();
于 2013-09-22T10:52:08.833 に答える