/**
  * @param \Illuminate\Database\Eloquent\Collection $dataCollection
  * @param array $columns
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function addOrder($dataCollection, $columns)
 {
     if (!isset($this->defaultSort['property'])) {
         $this->defaultSort = $this->findADefault($columns);
     }
     $this->sortedBy = Request::input('sortedBy', $this->defaultSort['property']);
     $this->sortAscending = Request::input('asc', $this->defaultSort['isAscending']);
     return $dataCollection->orderBy($this->sortedBy, $this->sortAscending ? 'ASC' : 'DESC');
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }