Skip to content

Commit

Permalink
[5.4] Add orderByDesc() to Query Builder (#18292)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco authored and taylorotwell committed Mar 10, 2017
1 parent cd84eca commit 4483e70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,19 @@ public function orderBy($column, $direction = 'asc')
return $this;
}

/**
* Add a descending "order by" clause to the query.
*
* @param string $column
* @return $this
*/
public function orderByDesc($column)
{
$this->orderBy($column, 'desc');

return $this;
}

/**
* Add an "order by" clause for a timestamp to the query.
*
Expand Down
4 changes: 4 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ public function testOrderBys()
$builder->select('*')->from('users')->orderBy('email')->orderByRaw('"age" ? desc', ['foo']);
$this->assertEquals('select * from "users" order by "email" asc, "age" ? desc', $builder->toSql());
$this->assertEquals(['foo'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->orderByDesc('name');
$this->assertEquals('select * from "users" order by "name" desc', $builder->toSql());
}

public function testHavings()
Expand Down

0 comments on commit 4483e70

Please sign in to comment.