php - Get latest values in GROUP BY using Laravel Eloquent ORM -


i'm trying understand how laravel's eloquent orm works , looking @ following mysql query:

select id, name, date tablename group name order date 

the use of group by returns oldest values of name. there way return latest value instead?

try following code,

tablename::select('id', 'name', db::raw('max(date) latest_date'))  ->groupby('name')  ->orderby('latest_date')  ->get() 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -