Reputation: 39
if have this relationship in my Place model:
public function openhours()
{
return $this->hasOne('Hours')->select(DB::raw("IF(CURTIME() BETWEEN open_time AND close_time ,'Open','Closed')"));
}
and in my routes:
$place = Place::with('openhours')->where('id', '=', 5)->get();
my table:
Table Name : hours
Fields :
id int(11)
place_id int(11)
open_time time
close_time time
table record:
id: 1
place_id: 5
open_time: 10:00:00
close_time: 17:00:00
it just returns:
openhours:null
When i run this query manually in phpmyadmin it works fine.
What am i doing wrong?
Thanks in advance.
Upvotes: 0
Views: 913
Reputation: 4110
Add the following into your App:before filter and you will get a dump of all the queries being executed and the bindings.
DB::listen(function($sql, $bindings, $time)
{
var_dump($sql);
var_dump($bindings);
});
Not an answer but it might help you see how the eloquent request compares to your own SQL.
Upvotes: 2