Use reorder() to clear previous orderBy clauses from a query builder before applying new sorting constraints.
When working with base query scopes or repository methods that already include an orderBy clause, calling orderBy() again appends a secondary sort rather than replacing the primary sort.
reorder() removes previously assigned order clauses cleanly.
Code Examples
use App\Models\User;
// Base query has default alphabetical ordering
$query = User::orderBy('name', 'asc');
// 1. Completely remove all ORDER BY clauses (runs without order constraints)
$unordered = (clone $query)->reorder()->get();
// 2. Clear previous sort and apply new ordering
$recentUsers = $query->reorder('created_at', 'desc')->get();
// SQL: select * from `users` order by `created_at` desc
Key Benefits
- Scope Overrides: Safely override hardcoded sorting rules defined in model global or local query scopes.
- Clean Reset: Calling
->reorder()without arguments resets the query's internal$ordersarray to empty. - Direction Flexibility: Accepts new column and direction arguments (
'asc'or'desc') in a single fluent call.
Related Tips
View all tips →Refresh and Pessimistically Lock Models with refreshForUpdate() in Laravel 13.27
Laravel 13.27 adds refreshForUpdate(), reloading an existing model instance in-place with fresh database attributes while acquiring an exclusive FOR UPDATE row lock.
Scope Pivot Table Queries with Closures in wherePivot() in Laravel 13.26
Laravel 13.26 allows wherePivot() and orWherePivot() to accept closures, enabling direct reuse of local scopes defined on custom Pivot models.