Laravel eloquent select not accepting if function

37 views Asked by At

I simply need to calculate a new field date in select in eloquent... but it does not seems to work although if I copy the mysql query in phpmyadmin it works.

 PV_Task::select("*,IF(date_start<'".$today."','".$today."',date_start) AS date")->whereRaw("project = 'xxx'")->orderByRaw('date asc, date_start asc, phase asc, sortorder asc')->get();

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 
 'IF(date_start<'2024-03-10','2024-03-10',date_start)' in 'field list' 

 select
   *,
   `IF(date_start<'2024-03-10','2024-03-10',date_start)` as `date`.   
 from
   `table`
 where
   (project = 'xxx')
 order by
   id asc

Of course, I can do it in not-eloquent... but I want to learn... Is it possible?

 selectRaw(as above) works fine
0

There are 0 answers