我试图将此传统sql
查询转换为larvael/lumen
查询构建器并进入砖墙。
$query = "SELECT a.id, a.name, a.cuisine, a.status, a.new, a.addressLine1, a.addressLine2, a.addressLine3, a.city, a.weekendot, a.weekendct, b.class
FROM restaurants a, restaurants_class b
WHERE a.class = b.id
AND '$date' = CURRENT_DATE
AND '$ntime' BETWEEN a.weekendot AND a.weekendct
ORDER BY id DESC";
$date
和$ntime
是变量。
这是我到目前为止所拥有的;
$posts = DB::connection('web')
->table('restaurants')
->join('restaurants_class', 'restaurants.class', '=', 'restaurants_class.id')
->select('restaurants.*', 'restaurants_class.*')
->get();
第一个AND
语句没有从DB
第二个AND
语句将var
与DB
不确定如何实施whereBetween
答案 0 :(得分:0)
这是完全未经测试的,但我认为您最好的选择是使用whereRaw
方法,因为您拥有的变量不允许您使用whereBetween
方法。
我还假设$date
和$ntime
变量是PHP变量而不是MySQL变量。
$posts = DB::connection('web')
->table('restaurants')
->join('restaurants_class', 'restaurants.class', '=', 'restaurants_class.id')
->whereRaw('? = CURRENT_DATE', $date)
->whereRaw('? BETWEEN a.weekendot AND a.weekendct', $ntime)
->select('restaurants.*', 'restaurants_class.*')
->get();