Here is my code for selecting reservations:
Reservation::select(array(
'obj_id',
'name',
'surname',
'date_from',
'date_to',
'days',
'status',
'slug',
'payable'
));
My question is how to change 'days' to get real diff between date_from
and date_to
? I don't have 'days' column in the database, I just want to count them in the SQL query.
In pure SQL should be something like that:
SELECT DATEDIFF('date_from, date_to) AS Days FROM RESERVATIONS;
How can I do that using Eloquent?
You can use DB::raw for this.
Reservation::select(array(
'obj_id', 'name', 'surname',
'date_from', 'date_to',
'days',
'status', 'slug', 'payable',
DB::raw("DATEDIFF(date_from,date_to)AS Days"))
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With