Reputation: 2261
How to get latest updated or created record in laravel
if i use latest() it only considered created_by value.
$tasks->latest();
if i use orderBy
$tasks->orderBy('created_at,'DESC');
then it is not working for latest updated.
$tasks->orderBy('updated_at,'DESC');
then its is not working for created_at
How to get latest created or latest updated Record. Basically, the most recent activity record? Thanks in advance!
Upvotes: 2
Views: 475
Reputation: 2657
$tasks->orderBy('updated_at,'DESC');
updated_at
is the most recent timestamp on any activity (created/updated), so this should work in both the cases.
Upvotes: 1