我想把这个查询转换成Laravel Eloquent语句:
select * from schedule where (now() between start_date and end_date);
我尝试使用whereBetween,但是遇到了一些错误。
$schedule = Schedule::whereBetween(Carbon::now(), ['start_date', 'end_date'])->get();
错误信息如下:
QueryException in Connection.php line 647: SQLSTATE[42S22]: Column not found: 1054 Unknown column '2017-06-01 06:17:30' in 'where clause' (SQL: select * from schedule where 2017-06-01 06:17:30 between start_date and end_date)
你有什么想法吗?
该错误是由于在 SQL 查询中使用了一个未知的列名“2017-06-01 06:17:30”,导致查询失败。可能需要检查列名是否正确,或者检查数据表中是否存在该列。
whereBetween
的第一个参数应该是列名,而不是值。 - Jerodev