original_string: protected function applySortingToQueryBuilder($query, $source, $direction = 'asc', $strategy = null)
      {
          $source = $source ?: $query->getModel()->getKeyName();
  
          // Prepare the sorting strategy
          if (null === $strategy) {
              $strategy = config('cms-models.meta-references.sort-strategy');
          }
  
          if ( ! $strategy) return $this;
  
  
          $strategyInstance = new $strategy;
  
          if ( ! ($strategyInstance instanceof SortStrategyInterface)) {
              throw new UnexpectedValueException("{$strategy} is not a sort strategy");
          }
  
          // Explode combined source keys and apply the strategy for each part
          foreach (explode(',', $source) as $sourcePart) {
  
              $query = $strategyInstance->apply($query, $sourcePart, $direction);
          }
  
          return $this;
      }
code: protected function applySortingToQueryBuilder($query, $source, $direction = 'asc', $strategy = null)
      {
          $source = $source ?: $query->getModel()->getKeyName();
  
          // Prepare the sorting strategy
          if (null === $strategy) {
              $strategy = config('cms-models.meta-references.sort-strategy');
          }
  
          if ( ! $strategy) return $this;
  
  
          $strategyInstance = new $strategy;
  
          if ( ! ($strategyInstance instanceof SortStrategyInterface)) {
              throw new UnexpectedValueException("{$strategy} is not a sort strategy");
          }
  
          // Explode combined source keys and apply the strategy for each part
          foreach (explode(',', $source) as $sourcePart) {
  
              $query = $strategyInstance->apply($query, $sourcePart, $direction);
          }
  
          return $this;
      }
code_tokens: protected function applySortingToQueryBuilder ( $ query , $ source , $ direction = 'asc' , $ strategy = null ) { $ source = $ source ? : $ query -> getModel ( ) -> getKeyName ( ) ; // Prepare the sorting strategy if ( null === $ strategy ) { $ strategy = config ( 'cms-models.meta-references.sort-strategy' ) ; } if ( ! $ strategy ) return $ this ; $ strategyInstance = new $ strategy ; if ( ! ( $ strategyInstance instanceof SortStrategyInterface ) ) { throw new UnexpectedValueException ( "{$strategy} is not a sort strategy" ) ; } // Explode combined source keys and apply the strategy for each part foreach ( explode ( ',' , $ source ) as $ sourcePart ) { $ query = $ strategyInstance -> apply ( $ query , $ sourcePart , $ direction ) ; } return $ this ; }
docstring: Applies sorting to a query builder, based on source string.
  
  @param Builder     $query
  @param string      $source
  @param string      $direction    sorting direction: 'asc' or 'desc'
  @param string|null $strategy
  @return $this
docstring_tokens: Applies sorting to a query builder based on source string .