orderByRaw() public method

Add a raw "order by" clause to the query.
public orderByRaw ( string $sql, array $bindings = [] )
$sql string
$bindings array
 /**
  * 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]);
 }
Example #2
0
 /**
  * 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);
 }
Example #3
0
 /**
  * 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");
 }