SELECT *
FROM (
SELECT *
FROM appointments
WHERE `date` <= Curdate()
) `t`
WHERE `t`.`end_time` <= current_time
Run Code Online (Sandbox Code Playgroud)
如何为此 SQL 查询编写 Laravel eloquent等效查询?
如果要查询:
date领域)+end_time没有过去(或正好是现在)的所有今天约会假设您有一个合适的appointment表模型,您可以尝试以下操作:
Appointments::where('appointments.date', '<', Carbon::now()->toDateString())
->orWhere(function ($query) {
$query->where('appointments.date', Carbon::now()->toDateString())
->where('appointments.end_time', '<=', Carbon::now()->toTimeString());
});
Run Code Online (Sandbox Code Playgroud)
您可能需要测试where子句中使用的 Carbon 格式以确保它与您的数据库存储格式匹配,并且查询返回预期结果。
| 归档时间: |
|
| 查看次数: |
152 次 |
| 最近记录: |