Skip to content

Commit f55d2a8

Browse files
committed
Add query builder reorder() documentation
1 parent b7995cb commit f55d2a8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

queries.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,20 @@ The `inRandomOrder` method may be used to sort the query results randomly. For e
590590
->inRandomOrder()
591591
->first();
592592

593+
#### reorder
594+
595+
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:
596+
597+
$query = DB::table('users')->orderBy('name');
598+
599+
$unorderedUsers = $query->reorder()->get();
600+
601+
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:
602+
603+
$query = DB::table('users')->orderBy('name');
604+
605+
$usersOrderedByEmail = $query->reorder('email', 'desc')->get();
606+
593607
#### groupBy / having
594608

595609
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:

0 commit comments

Comments
 (0)