From 254befb0db67a417296b791bc78baab372a4d7f7 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Thu, 9 Mar 2017 23:37:44 -0300 Subject: [PATCH] [5.4] Add orderByDesc() to Query Builder --- src/Illuminate/Database/Query/Builder.php | 13 +++++++++++++ tests/Database/DatabaseQueryBuilderTest.php | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 2f5d0db7ee4e..6e2fa3710b6d 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -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. * diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index eb0fdc1f18b7..101a4d7d8b90 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -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()