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

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

merged 1 commit into from
Mar 10, 2017

Conversation

KennedyTedesco
Copy link
Contributor

Just a shortcut of something that I use a lot.

@GrahamCampbell
Copy link
Member

👍

@taylorotwell taylorotwell merged commit 4483e70 into laravel:5.4 Mar 10, 2017
@KennedyTedesco KennedyTedesco deleted the builder-5.4 branch March 10, 2017 14:35
@joshmanders
Copy link
Contributor

So I'm on the fence about this... If we introduce orderByDesc($name) then shouldn't we have orderByAsc($name) too? Other wise inconsistencies...

Then I think, maybe a magic method, that does like orderByName('desc') and Name is column name, sorta like magic method for whereName('whatever').

Thoughts?

@KennedyTedesco
Copy link
Contributor Author

KennedyTedesco commented Mar 10, 2017

I don't think so. asc it's already implicit (see orderBy) and, after all, this is the default of MySQL (which is used by the majority of the devs):

The default sort order is ascending, with smallest values first. To sort in reverse (descending) order, add the DESC keyword. https://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html

@stefensuhat
Copy link

stefensuhat commented Mar 22, 2017

actually Laravel already provide latest and oldest. you can pass the argument column name. ex: latest('posted_at')

@aliusa
Copy link

aliusa commented Mar 23, 2017

orderByDesc() is more rememberable than latest()...

{
$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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants