本文整理匯總了PHP中Illuminate\Database\Eloquent\Model::orderBy方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::orderBy方法的具體用法?PHP Model::orderBy怎麽用?PHP Model::orderBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::orderBy方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: all
/**
* Retorna todos os registros deste Model.
*
* @param array $columns Colunas desejadas no retorno.
*
* @return mixed
*/
public function all($columns = ['*'])
{
if (!empty($this->defaultOrderColumn)) {
return $this->model->orderBy($this->defaultOrderColumn, $this->defaultOrderDirection)->get($columns);
}
return $this->model->get($columns);
}
示例3: orderBy
/**
* Order the results by the given column in the given direction.
*
* @param string $key
* @param string|null $direction
* @return $this
* @throws ModelNotSetException
*/
public function orderBy($key, $direction = 'asc')
{
if (!$this->model) {
throw new ModelNotSetException('You must set a model to run queries on.');
}
$this->model = $this->model->orderBy($key, $direction);
return $this;
}
示例4: applyOrder
/**
* @return $this
*/
public function applyOrder()
{
if (count($this->model->getQuery()->orders) === 0) {
$field = $this->orderField !== null ? $this->orderField : $this->getKeyName();
$direction = strtolower($this->orderDirection) === 'asc' ? 'asc' : 'desc';
$this->model = $this->model->orderBy($field, $direction);
}
return $this;
}
示例5: browse
/**
* List
*
* @param array $options
* @return array
*/
public static function browse($options = [])
{
if (empty($options)) {
return parent::all();
}
if (!empty($options['order'])) {
foreach ($options['order'] as $field => $direction) {
$find = parent::orderBy($field, $direction);
}
}
if (!empty($options['limit'])) {
$find = $find->take($options['limit']);
}
if (!empty($options['cursor'])) {
$find = $find->where('id', '<', $options['cursor']);
}
return $find->get();
}
示例6: updatePositions
/**
* @param int $parent_entity_id
* @return int
*/
public function updatePositions(int $parent_entity_id = null)
{
// we get the entities concerned by the position incrementation regarding the given previous entity
if ($parent_entity_id && ($parent_entity = $this->model->find($parent_entity_id))) {
// if a parent is defined
// we get the entities hierarchically inferiors to the parent
$other_entities = $this->model->where('position', '>', $parent_entity->position)->orderBy('position', 'desc')->get();
} else {
// if the entity has to be the master one
// we get all entities
$other_entities = $this->model->orderBy('position', 'desc')->get();
}
// we increment the position of the selected entities
foreach ($other_entities as $entities) {
$entities->position += 1;
$entities->save();
}
// we get the new position to apply it to the current entity
$new_position = isset($parent_entity) ? $parent_entity->position + 1 : 1;
return $new_position;
}
示例7: orderBy
/**
* Sets the order of the next query.
*
* @param string $column
* @param string $order
*
* @return void
*/
public function orderBy($column, $order = 'ASC')
{
$this->model = $this->model->orderBy($column, $order);
return $this;
}
示例8: findAll
public function findAll($orderColumn = 'create_at', $orderDir = 'desc')
{
return $this->model->orderBy($orderColumn, $orderDir)->get();
}
示例9: resolveAll
/**
* @return array
*/
public function resolveAll()
{
return $this->eloquent->orderBy('id')->get()->toArray();
}
示例10: apply
/**
* @param Model $model
* @param Repository $repository
*
* @return mixed
*/
public function apply(Model $model, Repository $repository)
{
return $model->orderBy($this->column, $this->direction);
}
示例11: all
/**
* Get all record of a table
*
* @param array $columns
* @param string $order
* @return mixed
*/
public function all($columns = array('*'), $order = 'asc')
{
return $this->model->orderBy('id', $order)->get($columns);
}
示例12: orderBy
public function orderBy($column, $direction = 'asc')
{
$this->model = $this->model->orderBy($column, $direction);
return $this;
}
示例13: orderBy
/**
* order by
* @param $attribute
* @param bool $desc 默認升序(false), 如需降序, 傳入 true
* @return static
*/
public function orderBy($attribute, bool $desc = false)
{
$this->original->orderBy($attribute, $desc ? 'desc' : 'asc');
return $this;
}
示例14: recent
/**
* Recent posts
* @param int $n How many post to show
*/
public static function recent($n = 5)
{
$articles = parent::orderBy('published_at', 'desc')->take($n)->get();
return $articles;
}