I'm working on an API endpoint with Laravel Spark.
This endpoint returns the given Team along with its users.
// in App\Team
public function users()
{
return $this->belongsToMany(
'App\User', 'team_users', 'team_id', 'user_id'
)->withPivot('role');
}
However, I wish to order those users by a method that is on the user model.
On my App\User model I have a method:
public function currentQueueLength()
{
returns an integer based upon the users current appointments,
}
Is there any way I can return the users relationship but order the users by the result of that method?