samedi 27 juillet 2019

conditional `orderBy` or `DB::Raw` inside `orderBy` in Laravel

I am trying to show appointment list in asc order for specific next days from today.(Ex:next 5 days or 10 days). Only from today, the next 5 days or 10 days(note: days will be dynamic, I mean client will setup).When today date will over then this date should not come into the days I mentioned(from today to next 5 days). I am trying with orderBy method something like bellow -

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

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

For sure, I am getting the bellow error -

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

What should I do to get the expected result, would someone help me please?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire