Illuminate\Database\Query\Builder::orderBy PHP Method

orderBy() public method

Add an "order by" clause to the query.
public orderBy ( string $column, string $direction = 'asc' )
$column string
$direction string
    public function orderBy($column, $direction = 'asc')
    {
        $this->{$this->unions ? 'unionOrders' : 'orders'}[] = ['column' => $column, 'direction' => strtolower($direction) == 'asc' ? 'asc' : 'desc'];
        return $this;
    }

Usage Example

 /**
  * 주어진 db query를 실행한다.
  *
  * @param Builder            $query      질의
  * @param int|int[]|stdClass $navigation 검색시 사용할 navigation(page, perPage, sort, order) 정보
  *
  * @return array
  */
 protected function executeQuery($query, $navigation = null)
 {
     // set default
     $order = $this->defaultOrder;
     $sort = $this->defaultSort;
     $perPage = $this->defaultPerPage;
     $page = null;
     if (is_array($navigation)) {
         list($page, $perPage) = $navigation;
     } elseif (is_object($navigation)) {
         $page = data_get($navigation, 'page', $page);
         $perPage = data_get($navigation, 'perPage', $perPage);
         $order = data_get($navigation, 'order', $order);
         $sort = data_get($navigation, 'sort', $sort);
     }
     if ($sort !== null) {
         $query->orderBy($sort, $order);
     }
     if ($navigation === null) {
         $collection = $query->get();
     } elseif ($page !== null) {
         $collection = $query->forPage($page, $perPage);
     } else {
         $collection = $query->paginate($perPage);
     }
     return $collection;
 }
All Usage Examples Of Illuminate\Database\Query\Builder::orderBy