protected function compileOneOrder($order, array &$bindings): string
    {
        if ($order instanceof Order) {
            return $this->compileIdentifier($order->column, $bindings).' '.($order->isDescending ? 'DESC' : 'ASC');
        }

        if ($order instanceof OrderByIsNull) {
            return $this->compileIdentifier($order->column, $bindings).' IS'.($order->areNullFirst ? ' NOT' : '').' NULL';
        }

        if ($order instanceof ExplicitOrder) {
            if (!$order->order) {
                return '';
            }

            $sql = 'CASE '.$this->compileIdentifier($order->column, $bindings);
            foreach (array_values($order->order) as $index => $value) {
                $sql .= ' WHEN '.$this->compileValue($value, $bindings).' THEN ?';
                $this->mergeBindings($bindings, [$index]);
            }
            $sql .= ' ELSE ?';
            $this->mergeBindings($bindings, [$order->areOtherFirst ? -1 : count($order->order)]);
            return $sql;
        }

        if ($order === 'random') {
            return 'RANDOM()';
        }

        throw new InvalidQueryException(sprintf(
            'The given order `%s` is unknown',
            is_string($order) ? $order : gettype($order)
        ));
    }
protected function compileOneOrder($order, array &$bindings): string
    {
        if ($order instanceof Order) {
            return $this->compileIdentifier($order->column, $bindings).' '.($order->isDescending ? 'DESC' : 'ASC');
        }

        if ($order instanceof OrderByIsNull) {
            return $this->compileIdentifier($order->column, $bindings).' IS'.($order->areNullFirst ? ' NOT' : '').' NULL';
        }

        if ($order instanceof ExplicitOrder) {
            if (!$order->order) {
                return '';
            }

            $sql = 'CASE '.$this->compileIdentifier($order->column, $bindings);
            foreach (array_values($order->order) as $index => $value) {
                $sql .= ' WHEN '.$this->compileValue($value, $bindings).' THEN ?';
                $this->mergeBindings($bindings, [$index]);
            }
            $sql .= ' ELSE ?';
            $this->mergeBindings($bindings, [$order->areOtherFirst ? -1 : count($order->order)]);
            return $sql;
        }

        if ($order === 'random') {
            return 'RANDOM()';
        }

        throw new InvalidQueryException(sprintf(
            'The given order `%s` is unknown',
            is_string($order) ? $order : gettype($order)
        ));
    }
protected function compileOneOrder ( $ order , array & $ bindings ) : string { if ( $ order instanceof Order ) { return $ this -> compileIdentifier ( $ order -> column , $ bindings ) . ' ' . ( $ order -> isDescending ? 'DESC' : 'ASC' ) ; } if ( $ order instanceof OrderByIsNull ) { return $ this -> compileIdentifier ( $ order -> column , $ bindings ) . ' IS' . ( $ order -> areNullFirst ? ' NOT' : '' ) . ' NULL' ; } if ( $ order instanceof ExplicitOrder ) { if ( ! $ order -> order ) { return '' ; } $ sql = 'CASE ' . $ this -> compileIdentifier ( $ order -> column , $ bindings ) ; foreach ( array_values ( $ order -> order ) as $ index => $ value ) { $ sql .= ' WHEN ' . $ this -> compileValue ( $ value , $ bindings ) . ' THEN ?' ; $ this -> mergeBindings ( $ bindings , [ $ index ] ) ; } $ sql .= ' ELSE ?' ; $ this -> mergeBindings ( $ bindings , [ $ order -> areOtherFirst ? - 1 : count ( $ order -> order ) ] ) ; return $ sql ; } if ( $ order === 'random' ) { return 'RANDOM()' ; } throw new InvalidQueryException ( sprintf ( 'The given order `%s` is unknown' , is_string ( $ order ) ? $ order : gettype ( $ order ) ) ) ; }
Converts a single order to an SQL query text.

@param Order|OrderByIsNull|ExplicitOrder|string $order Order. String `random` means that the order should be random.
@param array $bindings Bound values (array is filled by link)
@return string SQL text or an empty string
@throws InvalidQueryException
Converts a single order to an SQL query text .