field->getName()) ->snake() ->upper() ->prepend('PIVOT_'); return (string) match ($this->direction) { SortDirection::ASC => $name, SortDirection::DESC => $name->append('_DESC'), }; } /** * Apply the ordering to the current Eloquent builder. */ public function sort(Builder $builder): Builder { return $builder->orderBy( $this->relation?->qualifyPivotColumn($this->field->getColumn()), $this->direction->value ); } }