Ниже приведен следующий код и миграции, в результате чего были отобраны 3 лучших пользователя, набравших наибольшее количество баллов по моему приложению для викторины. Как я могу вытащить только топ-3 пользователей? Спасибо.
$results = DB::table('question_user')
->select(DB::raw('SUM(points) as total_points'),
'quiz_id', 'user_id')
->groupBy('quiz_id', 'user_id')
->orderBy('total_points', 'desc')
->take(5)->get();
Schema::create('question_user', function (Blueprint $table) {
$table->bigInteger('user_id');
$table->bigInteger('question_id');
$table->bigInteger('answer_id')->default(0);
$table->boolean('is_correct')->default(false);
$table->integer('points');
$table->integer('quiz_id');
$table->primary(['user_id', 'question_id']);