Order the data of a given table on the given column
and the given order

@param string $table
@param string $column
@param string $order
@param bool $trashed
@param \Illuminate\Database\DatabaseManager $db
@return object
968667
public function sort(
        $table,
        $column,
        $order,
        $trashed = false,
        DatabaseManager $db
    ) {
        $db = $db->connection();
        $data = $db->table($table);

        // Check for trashed data
        $data = $trashed ? $data->whereNotNull('deleted_at') : $data->whereNull('deleted_at');

        if ($table == 'users') {
            $data = $data->join('roles', 'users.role_id', '=', 'roles.id');
        }

        if ($table == 'posts') {
            $data = $data->join('statuses', 'posts.status_id', '=', 'statuses.id');
        }

        $data = $data
            ->orderBy($column, $order)
            ->paginate($this->config->items_per_page);

        return $data;
    }
280014
public static function orderBy($col = 'id', $type='asc')
    {
        try {
            self::init();
            $query = 'SELECT * FROM ' . self::$modelTable . ' ORDER BY '.$col. ' '.$type;
            return new QueryBuilder(self::$connect, $query);

        } catch (\Exception $exception) {
            var_dump($exception->getMessage());
        }
    }
1237688
protected function isOrdered(array $ordered)
    {

        // validate fields by exist in tables

        foreach ($ordered as $table => $sort) {

            // load model metaData

            if ($this->isModel($table) === true) {
                $model = (new Manager())->load($table, new $table);

                // check fields of table

                $this->validColumns($model->getModelsMetaData(), array_keys($sort), $table, $model);

                // check sort clause

                $sort = array_map('strtolower', $sort);

                if (empty($diff = array_diff(array_values($sort), $this->sort)) === false) {
                    throw new ExceptionFactory('Column', ['ORDER_TYPES_DOES_NOT_EXISTS', $diff]);
                }

                if (empty($diff = array_diff($sort, $this->sort)) === false) {
                    throw new ExceptionFactory('Column', ['ORDER_TYPES_DOES_NOT_EXISTS', $diff]);
                }

                $this->fields[$this->cast][$model->getSource()] = $sort;
            }
        }

        return true;
    }
1363094
public function orderBy($column, $how = 'ASC')
    {
        if (!array_key_exists('order_by', $this->query)) {
            $this->query['order_by'] = array();
        }

        // Multiple?
        if (is_array($column)) {
            foreach ($column as $col => $how) {
                $this->orderBy($col, $how);
            }
        } else {
            $this->query['order_by'][] = $this->columnName($column) . " {$how}";
        }
        return $this;
    }
405369
public function addOrder($column, $order = self::ORDER_ASC): void
    {
        if (!$this->checkOrderColumn($column)) {
            throw new GridException("Order for column `$column` is not allowed");
        }

        if (!$this->checkOrderName($order)) {
            throw new GridException("Order name for column `$column` is incorrect");
        }

        $this->orders[$column] = $order;
    }
1371258
public function addSort($column, $order = self::ASC)
    {
        //argument test
        Argument::i()
            //Argument 1 must be a string
            ->test(1, 'string')
            //Argument 2 must be a string
            ->test(2, 'string');
        
        if ($order != self::DESC) {
            $order = self::ASC;
        }
        
        $this->sort[$column] = $order;
        
        return $this;
    }
418982
public static function findColumns (array $columns, int $limit=0, string $order="DESC")
	{
		$order 	   	= static::validateOrder($order);
        $dbObject  	= Database::getInstance();
		$columns 	= joinArray($dbObject->escapeValues($columns), ', ');
		return static::limitFindBySql("SELECT {$columns} FROM ".static::$tableName." ORDER BY id {$order}", $limit);
	}
1042846
public function orderBy($order = null) {
		if (is_null($order)) //remove option
			return $this->discard('query.orderBy');
			
		return $this->merge(['query.orderBy' => func_get_args()]);
	}
582742
public function sort(Table $table)
    {
        $column = $table->getSortColumn();
        $dir = $table->getSortDir();

        if (!$column)
            return;

        $sqlId = null;
        foreach ($table->getColumns() as $id => $params) {
            if ($id == $column) {
                $sqlId = $params['sql_id'];
                break;
            }
        }

        if (!$sqlId)
            throw new \Exception("No 'sql_id' for column: $column");

        $qb = $this->getQueryBuilder();
        $qb->addOrderBy($sqlId, $dir);
    }
1141580
public function order_by($field, $table, $direction = '') {
        $direction = self::normalize_direction($direction);
        $this->order[] = self::resolve_field($field, $table) . ' ' . $direction;
    }
667404
function orderBy($column, $dir = null) {
		if (null !== $dir && '' !== $dir) {
			$dir = strtoupper($dir);
			if ($dir !== self::ASC && $dir !== self::DESC) {
				throw new RuntimeException("$dir is not a valid sorting direction.");
			}
			$column .= ' ' . $dir;
		}
		$this->orders[] = trim($column);
		return $this;
	}
103076
public function addOrderByLocate($searchable_string, $field , $table = ''): self
    {
        // No table provided
        if (!$table) {
            $table = $this->getDbTableName();
        }

        $this->order_fields[] = [
            'table' => $table,
            'type'  => 'string',
            'field' => 'LOCATE ("'. $this->dao::sql_prepare($searchable_string) .'", `'. $table .'`.`'. $field .'`)'
        ];

        return $this;
    }
230160
public function dbDelete($table, $item, $key = 'id')
    {
        $result = Eresus_CMS::getLegacyKernel()->db->
            delete($this->__table($table), "`$key` = '".(is_array($item)? $item[$key] : $item)."'");

        return $result;
    }
425794
protected function orderByMapped(Builder $query, ArgumentBag $args, $table, $column, $target)
    {
        $query->with($target)->getQuery()->orderBy("{$table}.{$column}", $args->get('direction'));

        return $query;
    }
940750
public function dropColumn($column, $table = null)
    {
        return $this->db->alterTable($this->getTable($table))
                        ->dropColumn($column)
                        ->execute();
    }
358857
function orderBy( $column, $direction = "ASC" ) {

        $clone = clone $this;

        if ($direction===true) {
            $clone->orderBy[] = $column;
        }else{
            $clone->orderBy[] = $this->db->quoteIdentifier( $column ) . " " . $direction;
        }

        return $clone;

    }
214692
public function orderBy($col = 'id', $type='asc')
    {
        try {
            if (!is_null($this->query)) {
                $this->query .= ' ORDER BY '.$col. ' '.$type;
                return $this;
            }

        } catch (\Exception $exception) {
            var_dump($exception->getMessage());
        }
    }