Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

plue's avatar
Level 1

get last record by date

hi! how do I get the last record by date? this return the first record by date

$station = Station::groupBy('date')->orderBy('date', 'DESC')->get();
0 likes
2 replies
Rumnaz khan's avatar

Try this:

$station = Station::whereIn('id', function($query) {
                       $query->from('station')->groupBy('date')->selectRaw('MAX(id)');
                    })->get();

Please or to participate in this conversation.