本文整理汇总了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");
}