@param \Illuminate\Database\Query\Builder $query
@param string                             $order
@param string                             $direction
@param mixed                              $after

@return \Illuminate\Database\Query\Builder
775778
protected function setAfter($query, $order, $direction, $after)
    {
        if ($after == 0) {
            return $query;
        }

        return $query->where($order, ($direction === 'desc' ? '<' : '>'), $after);
    }
456469
public function orderBy($fields, string $direction = 'ASC'): IQueryBuilderHandler
    {
        if (\is_array($fields) === false) {
            $fields = [$fields];
        }

        foreach ((array)$fields as $key => $value) {
            $field = $key;
            $type = $value;

            if (\is_int($key) === true) {
                $field = $value;
                $type = $direction;
            }

            if (($field instanceof Raw) === false) {
                $field = $this->addTablePrefix($field);
            }

            $this->statements['orderBys'][] = compact('field', 'type');
        }

        return $this;
    }
1294824
public function orderBy($orderBy, $direction='asc')
    {
        if($direction == 'desc')
            return $this->model->orderBy($orderBy, 'desc');
        else
            return $this->model->orderBy($orderBy, 'asc');
    }
967264
public function setOrderBy($sort, $direction = 'ASC')
    {
        $this->sort = $sort;
        $this->direction = $direction;
        return $this;
    }
660679
public function apply($query, $column, $direction = 'asc')
    {
        $direction = $direction === 'desc' ? 'desc' : 'asc';

        $modelTable = $query->getModel()->getTable();
        $modelKey   = $query->getModel()->getKeyName();

        $query->orderBy("{$modelTable}.{$modelKey}", $direction);

        return $query;
    }
784780
public function sort($column, $direction = 'asc')
    {
        if (is_int($direction)) {
            $direction = ($direction == -1) ? 'desc' : 'asc';
        }
        $this->query->orderBy($column, $direction);

        return $this;
    }
75621
public function orderBy($field, $direction = 1)
    {
        if (is_string($direction)) {
            $direction = $direction === 'asc' ? 1 : -1;
        }

        $this->orderBy[$field] = $direction;

        return $this;
    }
727338
protected function compileOrders(Builder $query, $orders)
    {
        if (empty($orders)) {
            return '';
        }

        return 'order by '.implode(', ', array_map(function ($order) {
            if (isset($order['sql'])) {
                return $order['sql'];
            }

            return $this->wrap($order['column']).' '.$order['direction'];
        }, $orders));
    }
1243154
public function getFileErrors($order = 'error.counter', $direction = 'DESC')
    {
        $this->getAll(true);

        /** @var QueryBuilder $qb */
        $qb = $this->qb;

        return $qb
            ->andWhere('error.type = :type')
            ->setParameter('type', HttpError::TYPE_FILE)
            ->orderBy($order, $direction);
    }
110291
public function orderBy($key, $direction = \Parable\ORM\Query::ORDER_ASC)
    {
        $this->orderBy = ['key' => $key, 'direction' => $direction];
        return $this;
    }
452560
public function orderBy($column, $direction = 'ASC')
    {
        $orderVal         = [
            'ASC'  => 1,
            'DESC' => -1,
        ];
        $this->ordering[] = [
            'column'    => $column,
            'direction' => $orderVal[strtoupper($direction)],
        ];

        return $this;
    }
278598
public function add_sort($field, $direction = 'ASC') {
        if (!isset($this->_query_modifiers['sort'])) {
            $this->_query_modifiers['sort'] = array();
        }

        $this->_query_modifiers['sort'][$field] = $direction;
    }
1306093
public function scopeOrderByViews(Builder $query, string $direction = 'desc', $period = null): Builder
    {
        return $query->withCount(['views' => function ($query) use ($period) {
            if ($period) {
                $query->withinPeriod($period);
            }
        }])->orderBy('views_count', $direction);
    }
67863
final public function orderBy($orderby, $direction = '')
    {
        if (strtolower($direction) == 'random') {
            $orderby = ''; // Random results want or don't need a field name
            $direction = $this->_randomKeyword;
        } elseif (trim($direction) != '') {
            $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' ' . $direction : ' ASC';
        }


        if (strpos($orderby, ',') !== FALSE) {
            $temp = array();
            foreach (explode(',', $orderby) as $part) {
                $part = trim($part);
                if (!in_array($part, $this->arrayAliasedTables)) {
                    $part = $this->identifiers(trim($part));
                }
                $temp[] = $part;
            }

            $orderby = implode(', ', $temp);
        } else if ($direction != $this->_randomKeyword) {
            $orderby = $this->identifiers($orderby);
        }

        $orderbyStatement = $orderby . $direction;

        $this->arrayOrderBy[] = $orderbyStatement;
        if ($this->arrayCaching === TRUE) {
            $this->arrayCacheOrderBy[] = $orderbyStatement;
            $this->arrayCacheExists[] = 'orderby';
        }

        return $this;
    }
445213
public function orderBy($column, $direction = 'asc')
    {
        $this->{$this->unions ? 'unionOrders' : 'orders'}[] = [
            'column' => $column,
            'direction' => strtolower($direction) == 'asc' ? 'asc' : 'desc',
        ];

        return $this;
    }
260545
public function order_by($property, $direction = 'ASC')
	{
		if (is_array($property))
		{
			foreach ($property as $p => $d)
			{
				if (is_int($p))
				{
					is_array($d) ? $this->order_by($d[0], $d[1]) : $this->order_by($d, $direction);
				}
				else
				{
					$this->order_by($p, $d);
				}
			}
			return $this;
		}

		// prefix table alias when not yet prefixed and not a DB expression object
		if ( ! $property instanceof \Fuel\Core\Database_Expression and strpos($property, '.') === false)
		{
			$property = $this->alias.'.'.$property;
		}

		$this->order_by[] = array($property, $direction);

		return $this;
	}
523446
public function getRouteErrors($order = 'error.counter', $direction = 'DESC')
    {
        $this->getAll(true);

        /** @var QueryBuilder $qb */
        $qb = $this->qb;

        return $qb
            ->andWhere('error.type = :type')
            ->setParameter('type', HttpError::TYPE_ROUTE)
            ->orderBy($order, $direction);
    }