[12.x] Add inOrderOf() method to query builder#59162
[12.x] Add inOrderOf() method to query builder#59162taylorotwell merged 1 commit intolaravel:12.xfrom
Conversation
|
Nice addition 👏 |
|
+1 |
|
my orderByRaw('FIELD(...)') snippets are finally getting a proper retirement |
|
love additions like this. anything that keeps me out of raw SQL is a win. |
|
Why not use |
|
Looks good to me. The $values parameter should also support enums. |
|
It already does. |
Adds an
inOrderOf()method to the query builder for ordering results by a given sequence of values.Sorting by a specific value order is a common need (e.g. status-based sorting in e-commerce, priority-based sorting in task management). Today this requires
orderByRaw()with a manualCASEexpression, which is verbose and error-prone.The method compiles to a parameterized
CASEclause, places unmatched values after the given sequence, and chains naturally with existingorderBy()calls.Tests cover the query builder and MySQL, PostgreSQL, and SQL Server grammars.
No breaking changes.