so I'm trying to get duplicate data with the higher ID number so I can delete the latest duplicate data (not the older one).
I've tried using orderBy but it won't work
$duplicates = MasterPayrollInput::where('periode', $month)
->orderBy('id', 'asc')
->groupBy('nip')
->havingRaw('count(*) > 1')
->get();
$duplicatesid = array_column($duplicates->toArray(), 'id');
$todelete = array_map(function($item){ return $item[0]; }, $duplicatesid);
MasterPayrollInput::whereIn('id', $duplicatesid )->delete();