本文整理匯總了PHP中Illuminate\Database\Query\Builder::orderByRaw方法的典型用法代碼示例。如果您正苦於以下問題:PHP Builder::orderByRaw方法的具體用法?PHP Builder::orderByRaw怎麽用?PHP Builder::orderByRaw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::orderByRaw方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: scopeOrderByRandom
/**
* Scope to order by random.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder
*/
public function scopeOrderByRandom($query)
{
static $randomFunctions = ['mysql' => 'RAND()', 'pgsql' => 'RANDOM()', 'sqlite' => 'RANDOM()', 'sqlsrv' => 'NEWID()'];
$driver = $this->getConnection()->getDriverName();
return $query->orderByRaw($randomFunctions[$driver]);
}
示例2: orderByRaw
/**
* Add a raw "order by" clause to the query.
*
* @param string $sql
* @param array $bindings
* @return $this
* @static
*/
public static function orderByRaw($sql, $bindings = array())
{
return \Illuminate\Database\Query\Builder::orderByRaw($sql, $bindings);
}
示例3: scopeAdminFirst
/**
* Admin luôn đứng đầu
* Chú ý gọi query này trước các quyery orderBy khác
*
* @param \Illuminate\Database\Query\Builder $query
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeAdminFirst($query)
{
return $query->orderByRaw("`users`.`role`='super_admin' DESC")->orderByRaw("`users`.`role`='admin' DESC");
}