/** * @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; }
/** * 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); }
/** * 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; }
/** * @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; }
/** * 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(); }
/** * @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; }
/** * 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; }
public function findAll($orderColumn = 'create_at', $orderDir = 'desc') { return $this->model->orderBy($orderColumn, $orderDir)->get(); }
/** * @return array */ public function resolveAll() { return $this->eloquent->orderBy('id')->get()->toArray(); }
/** * @param Model $model * @param Repository $repository * * @return mixed */ public function apply(Model $model, Repository $repository) { return $model->orderBy($this->column, $this->direction); }
/** * 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); }
public function orderBy($column, $direction = 'asc') { $this->model = $this->model->orderBy($column, $direction); return $this; }
/** * 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; }
/** * 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; }