Commit 93b7afd5 authored by Jens Segers's avatar Jens Segers

Added natural sorting, fixes #148

parent c1af77aa
......@@ -281,9 +281,18 @@ class Builder extends \Illuminate\Database\Query\Builder {
* @param string $direction
* @return Builder
*/
public function orderBy($column, $direction = 'asc')
public function orderBy($column, $direction = null)
{
$this->orders[$column] = (strtolower($direction) == 'asc' ? 1 : -1);
if (is_null($direction) && $column == 'natural')
{
$this->orders['$natural'] = 1;
}
else
{
$direction = $direction ?: 'asc';
$this->orders[$column] = (strtolower($direction) == 'asc' ? 1 : -1);
}
return $this;
}
......
......@@ -147,6 +147,9 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$user = User::whereNotNull('age')->orderBy('age', 'desc')->first();
$this->assertEquals(37, $user->age);
$user = User::whereNotNull('age')->orderBy('natural')->first();
$this->assertEquals(35, $user->age);
}
public function testGroupBy()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment