relation; } /** * Apply the ordering to the current Eloquent builder. */ public function sort(Builder $builder): Builder { $relation = $builder->getRelation($this->relation); $orderBySubQuery = $relation->getRelationExistenceQuery($relation->getQuery(), $builder, [$this->column]); return $builder->orderBy($orderBySubQuery->toBase(), $this->direction->value); } }