本文整理汇总了PHP中Builder::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::orderBy方法的具体用法?PHP Builder::orderBy怎么用?PHP Builder::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder::orderBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doOrdering
/**
* Datatable ordering
*
* @return null
*/
private function doOrdering()
{
if (array_key_exists('order', $this->input) && count($this->input['order']) > 0) {
for ($i = 0, $c = count($this->input['order']); $i < $c; $i++) {
$order_col = (int) $this->input['order'][$i]['column'];
$order_dir = $this->input['order'][$i]['dir'];
if ($this->new_version) {
$column = $this->input['columns'][$order_col];
if ($column['orderable'] == "true") {
if (!empty($column['name'])) {
$this->query->orderBy($column['name'], $order_dir);
} elseif (isset($this->columns[$order_col])) {
$column_name = $this->getColumnName($this->columns[$order_col]);
$this->query->orderBy($column_name, $order_dir);
}
}
} else {
if (isset($this->columns[$order_col])) {
if ($this->input['columns'][$order_col]['orderable'] == "true") {
$column_name = $this->getColumnName($this->columns[$order_col]);
$this->query->orderBy($column_name, $order_dir);
}
}
}
}
}
}
示例2: 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);
}
}
}
}
示例3: options
/**
* Set query options and params
* @param array $options
* @return Builder
*/
public function options($options = array())
{
// Get order options
$orderBy = array_get($options, 'order_by', 'created_at');
$order = array_get($options, 'order', 'desc');
// Run order
if ($orderBy == 'rand') {
$this->query->orderBy(DB::raw('RAND()'), $order);
} else {
$this->query->orderBy($orderBy, $order);
}
// Also the limit
if ($limit = array_get($options, 'limit')) {
$this->defaultLimit = (int) $limit;
}
if (is_array($options)) {
foreach ($options as $key => $value) {
if (!in_array($key, array('limit', 'order_by'))) {
if (is_array($value)) {
$this->query->where($key, $value[0], $value[1]);
} else {
$this->query->where($key, $value);
}
}
}
}
return $this->query;
}
示例4: scopeOrderByNameAsc
/**
* Order by name ascending scope
*
* @param Builder $query The current query to append to
*
* @return Builder
*/
public function scopeOrderByNameAsc($query)
{
return $query->orderBy('username', 'asc');
}
示例5: scopeNewest
/**
* Order by created at
*
* @param Builder $query
* @return Builder
*/
public function scopeNewest($query)
{
return $query->orderBy('created_at', 'DESC');
}