From f55d2a8e350c6509318c9ec9b3e0ae71fb01e71b Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Tue, 31 Mar 2020 11:29:15 -0400 Subject: [PATCH 1/2] Add query builder reorder() documentation --- queries.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/queries.md b/queries.md index 3d03bc13fa9..d9f1bd2c871 100644 --- a/queries.md +++ b/queries.md @@ -590,6 +590,20 @@ The `inRandomOrder` method may be used to sort the query results randomly. For e ->inRandomOrder() ->first(); +#### reorder + +The `reorder` method allows you to remove all the existing orders and optionally apply a new order. For example, you can remove all the existing orders: + + $query = DB::table('users')->orderBy('name'); + + $unorderedUsers = $query->reorder()->get(); + +To apply a new order at the same time, include the column you wish to sort by as the first argument and the direction as the second argument: + + $query = DB::table('users')->orderBy('name'); + + $usersOrderedByEmail = $query->reorder('email', 'desc')->get(); + #### groupBy / having The `groupBy` and `having` methods may be used to group the query results. The `having` method's signature is similar to that of the `where` method: From 868d6f5b4b7d371762daa6da19628d57dd149c45 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 1 Apr 2020 08:54:30 -0500 Subject: [PATCH 2/2] Update queries.md --- queries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries.md b/queries.md index d9f1bd2c871..16c39935734 100644 --- a/queries.md +++ b/queries.md @@ -598,7 +598,7 @@ The `reorder` method allows you to remove all the existing orders and optionally $unorderedUsers = $query->reorder()->get(); -To apply a new order at the same time, include the column you wish to sort by as the first argument and the direction as the second argument: +To remove all existing orders and apply a new order, provide the column and direction as arguments to the method: $query = DB::table('users')->orderBy('name');