本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::orderBy方法的具体用法?PHP Builder::orderBy怎么用?PHP Builder::orderBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::orderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onQuerying
/**
* Fired just before querying
* for table entries.
*
* @param Builder $query
*/
public function onQuerying(Builder $query)
{
$uploaded = $this->getUploaded();
$query->whereIn('id', $uploaded ?: [0]);
$query->orderBy('updated_at', 'ASC');
$query->orderBy('created_at', 'ASC');
}
示例2: orderBy
/**
* Adds a OrderBy to the query
*
* @param string
* @param string
* @return $this
*/
public function orderBy($column, $order = 'asc')
{
if ($column != null) {
$this->query->orderBy($column, $order);
}
return $this;
}
示例3: applyOrderBy
/**
* @param string $column
* @param string $direction
* @return $this
*/
public function applyOrderBy($column, $direction = 'asc')
{
/**
* Save to conditons.
*/
$this->addCondition('order by', [$column, $direction]);
$this->model = $this->model->orderBy($column, $direction);
return $this;
}
示例4: orderByColumns
/**
* Order by columns based on parameters
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $orderBy
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function orderByColumns(Builder $query, $orderBy)
{
if (Request::has('orderbycolumn') == TRUE && Request::has('orderbytype') == TRUE) {
$query->orderBy(Request::input('orderbycolumn'), Request::input('orderbytype'));
} else {
foreach ($orderBy as $orderByColumn => $orderByType) {
$query->orderBy($orderByColumn, $orderByType);
}
}
return $query;
}
示例5: scopeSort
/**
* Sort
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param string|null $sort Optional sort string
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeSort(Builder $builder, $sort = null)
{
if ((is_null($sort) || empty($sort)) && Input::has($this->getSortParameterName())) {
$sort = Input::get($this->getSortParameterName());
}
if (!is_null($sort)) {
$sort = explode(',', $sort);
foreach ($sort as $field) {
$field = trim($field);
$order = 'asc';
switch ($field[0]) {
case '-':
$field = substr($field, 1);
$order = 'desc';
break;
case '+':
$field = substr($field, 1);
break;
}
$field = trim($field);
if (in_array($field, $this->getSortable())) {
$builder->orderBy($field, $order);
}
}
}
}
示例6: onQuerying
/**
* Fired just before querying
* for table entries.
*
* @param Builder $query
*/
public function onQuerying(Builder $query)
{
$uploaded = $this->getUploaded();
if ($fieldType = $this->getFieldType()) {
/*
* If we have the entry available then
* we can determine saved sort order.
*/
$entry = $fieldType->getEntry();
$table = $fieldType->getPivotTableName();
if ($entry->getId() && !$uploaded) {
$query->join($table, $table . '.file_id', '=', 'files_files.id');
$query->where($table . '.entry_id', $entry->getId());
$query->orderBy($table . '.sort_order', 'ASC');
} else {
$query->whereIn('id', $uploaded ?: [0]);
}
} else {
/*
* If all we have is ID then just use that.
* The JS / UI will be handling the sort
* order at this time.
*/
$query->whereIn('id', $uploaded ?: [0]);
}
}
示例7: process
/**
* @param Builder $src
* @param OperationInterface|SortOperation $operation
* @return mixed
*/
public function process($src, OperationInterface $operation)
{
$field = $operation->getField();
$order = $operation->getOrder();
$src->orderBy($field, $order);
return $src;
}
示例8: scopeSort
/**
* Adds a sort scope.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $column
* @param string $direction
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSort(Builder $query, $column, $direction)
{
if (!in_array($column, $this->sortable)) {
return $query;
}
return $query->orderBy($column, $direction);
}
示例9: parseSort
protected function parseSort(array $params, Query $query)
{
if (!isset($params['sort'])) {
return $query->orderBy('id', 'desc');
}
$column = strtolower($params['sort']);
$direction = 'asc';
if (strpos($params['sort'], '-') === 0) {
$direction = 'desc';
$column = ltrim($column, '-');
}
if (!in_array($column, Unit::getColumns())) {
return $query->orderBy('id', 'desc');
}
return $query->orderBy($column, $direction);
}
示例10: apply
public function apply(Builder $builder, Model $model)
{
$table = $model->getTable();
$columns = $model->getDefaultOrderableColumns() ?: [];
foreach ($columns as $column => $order) {
$builder->orderBy("{$table}.{$column}", $order);
}
}
示例11: apply
/**
* Apply scope on the query
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
*/
public function apply(Builder $builder, Model $model)
{
$columns = $model->getQualifiedOrderByColumns();
foreach ($columns as $column => $direction) {
$builder->orderBy($column, $direction);
}
$this->addUnordered($builder);
}
示例12: sortBy
/**
* @param $field
* @param $direction
*
* @return $this
*/
protected function sortBy($field, $direction)
{
if (!in_array($direction, [DoplioDbTable::SORT_ASC, DoplioDbTable::SORT_DESC])) {
throw new \InvalidArgumentException(sprintf('%s is an invalid sort direction'), $direction);
}
$this->specificationQuery->orderBy($field, $direction);
return $this;
}
示例13: scopeOrder
/**
* Orders a given query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOrder($query)
{
if ($this->orderBy[0] !== null and $this->orderBy[1] !== null) {
return $query->orderBy($this->orderBy[0], $this->orderBy[1]);
}
// If the orderBy values are invalid, let's just return the query for now.
return $query;
}
示例14: apply
/**
* Applies criterion to query.
*
* @param Builder $builder query builder
*/
public function apply(Builder $builder)
{
$sortMethod = 'sort' . studly_case($this->getField());
if (method_exists($builder->getModel(), $sortMethod)) {
call_user_func_array([$builder->getModel(), $sortMethod], [$builder, $this->getOrder()]);
} else {
$builder->orderBy($this->getField(), $this->getOrder());
}
}
示例15: direction
/**
* Set the direction of the query.
*
* @param string|null $direction The date direction to order by
* @return Parser The parser instance itself
*/
public function direction($direction = null)
{
if ($direction == 'Latest') {
$this->query->orderBy('created_at', 'desc');
} elseif ($direction == 'Oldest') {
$this->query->orderBy('created_at', 'asc');
}
return $this;
}