Eloquent get user with highest relation table points

  eloquent, laravel, php

I’m trying to get the user with the highest evaluation points based on charisma and persuasion

What i have wrote so far after this i couldn’t figure out how to make it work

    $user = User::where('commision_id', $data['commision'])->whereHas('role', function ($q) {
        $q->where('level', 2);
    })->with(['evaluations' => function ($q) {

The evaluations relation migration

    Schema::create('evaluations', function (Blueprint $table) {


So basically i have to sum the exp points based on persuasion and the exp points based on charisma then sum both of those sum values to get the highest ranking user.

Source: Laravel

Leave a Reply