gpt4 book ai didi

mysql - Laravel 中的条件 `orderBy` 或 `DB::Raw` inside `orderBy`

转载 作者:行者123 更新时间:2023-11-29 15:44:21 29 4
gpt4 key购买 nike

我正在尝试以 asc 顺序显示从今天开始的特定接下来几天的约会列表。(例如:接下来的 5 天或 10 天)。仅从今天开始,接下来的 5 天或 10 天(注意:天数将是动态的,我的意思是客户将设置)。当今天日期结束时,该日期不应进入我提到的日子(从今天到接下来的5天)。我正在尝试使用 orderBy 方法,如下所示 -

$today = date('Y-m-d');
$appointments = Appointment::with('Customer')
->orderBy(DB::raw("('appointment_time', '>=', ${today})"), 'asc')->get();

return view("ManageAppointment", compact(['appointments']));

当然,我收到了以下错误 -

SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s) (SQL: select * from appointments order by ('appointment_time', '>=', 2019-07-27) asc)

我应该怎么做才能得到预期的结果,有人可以帮助我吗?

最佳答案

尝试一下。

$tomorrow = Carbon::tomorrow(); //2019-07-28 00:00:00
$nextdate = Carbon::now()->addDays(5); //dynamic day(5days, 10days) //2019-08-01 00:00:00

$appointments = Appointment::with('Customer')
->whereBetween('appointment_time', [$tomorrow,$nextdate])
->orderBy('appointment_time','asc')->get();

关于mysql - Laravel 中的条件 `orderBy` 或 `DB::Raw` inside `orderBy`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57233048/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com