Skip to content

Commit f0f7b04

Browse files
committed
fix(laravel): fix default order parameter
Closes: #6839 Signed-off-by: Tobias Oitzinger <[email protected]>
1 parent 2d59c63 commit f0f7b04

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Laravel/Eloquent/State/CollectionProvider.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5858
$query = $extension->apply($query, $uriVariables, $operation, $context);
5959
}
6060

61+
$order = $operation->getOrder();
62+
if (null !== $order) {
63+
$isList = array_is_list($order);
64+
foreach ($operation->getOrder() ?? [] as $property => $direction) {
65+
if ($isList) {
66+
$property = $direction;
67+
$direction = 'ASC';
68+
}
69+
70+
if (str_contains($property, '.')) {
71+
[$table, $property] = explode('.', $property);
72+
73+
// Relation Order by, we need to do laravel eager loading
74+
$query->with([
75+
$table => fn ($query) => $query->orderBy($property, $direction),
76+
]);
77+
78+
continue;
79+
}
80+
81+
$query->orderBy($property, $direction);
82+
}
83+
}
84+
6185
if (false === $this->pagination->isEnabled($operation, $context)) {
6286
return $query->get();
6387
}

0 commit comments

Comments
 (0)