我正在尝试以 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/