How to write about laravel sorting first and grouping later

I know the original, but I can"t write it in the laravel way, because there are still pages in the back. It"s too troublesome to write your own pages. Which god would like to talk about it? thank you.
the following is the native sql

.

select * from (select f.idrecoveryf.useraccounidreu.nicknamedirection f.signrecoveryf.contentPowerf.statusreachf.useraccounipjournal f.setconsumtime from feedback as users as u where f.user_id=u.id order by set_time desc) as t group by t.user_id

Mar.20,2021

The

field is a little different. Change it yourself

DB::enableQueryLog();

$subQuery = DB::table(DB::raw('`feedback` as f,`users` as u'))
    ->where('f.user_id', '=', DB::raw('`u`.`id`'))
    ->orderBy('f.created_at', 'desc')
    ->select(['f.id', 'f.user_id', 'u.name', 'f.content', 'f.created_at']);
$query = DB::table(DB::raw("({$subQuery->toSql()}) as t"))
    ->mergeBindings($subQuery)
    ->groupBy('t.user_id')
    ->get(['t.*']);

$result = DB::getQueryLog();

print_r($result);

printed result:

Array
(
    [0] => Array
        (
            [query] => select `t`.* from (select `f`.`id`, `f`.`user_id`, `u`.`name`, `f`.`content`, `f`.`created_at` from `feedback` as f,`users` as u where `f`.`user_id` = `u`.`id` order by `f`.`created_at` desc) as t group by `t`.`user_id`
            [bindings] => Array
                (
                )

            [time] => 112.89
        )

)
Menu