orderByRaw() Eloquent in laravel
You need to write an eloquent query and order the result by the difference of two columns.
orderBy query:
Stud::where('created_at', '>', '2020-03-08)
->orderBy('updated_at', 'desc')
->get();
the difference between updated_at and created_at?
Stud::where('created_at', '>', '2020-03-08')
->orderByRaw('(updated_at - created_at) desc')
->get();
orderByRaw()
orderByRaw() method will apply order by clause without changing anything in it.
select * from table
where created_at > '2020-03-08'
order by (updated_at - created_at) desc