Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Add orderByDesc() to Query Builder #18292

Merged
merged 1 commit into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use

    public function orderByDesc($column)
    {
        return $this->orderBy($column, 'desc');
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you go @CupOfTea696 #18465

Thanks. 😄

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be perfect

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

}

/**
* 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