Skip to content

Commit 3088b7c

Browse files
committed
fix: sortables
1 parent 4a6ed28 commit 3088b7c

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/Filters/SortCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function inRepository(RestifyRequest $request, Repository $repository): s
5252
{
5353
$collection = static::make($repository::sorts())->merge(
5454
$repository::collectRelated()->mapIntoSortable($request)
55-
);
55+
)->merge($repository::collectFieldSorts($request, $repository));
5656

5757
return $this->filter(fn (SortableFilter $filter) => $collection->contains('column', '=', $filter->column));
5858
}

src/Traits/InteractWithSearch.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public static function collectWiths(RestifyRequest $request, Repository $reposit
4949
public static function lazyLoadedFieldsRelationship(RestifyRequest $request, Repository $repository): array
5050
{
5151
return $repository->collectFields($request)
52-
->filter(fn (Field $field) => $field->isLazy($request))
53-
->map(fn (Field $field) => $field->getLazyRelationshipName())
52+
->filter(fn(Field $field) => $field->isLazy($request))
53+
->map(fn(Field $field) => $field->getLazyRelationshipName())
5454
->all();
5555
}
5656

@@ -93,8 +93,6 @@ public static function collectSortables(RestifyRequest $request, Repository $rep
9393
*/
9494
public static function collectSorts(RestifyRequest $request, Repository $repository): SortCollection
9595
{
96-
$fieldSorts = static::collectFieldSorts($request, $repository);
97-
9896
$requestSorts = (new SortCollection(explode(',', $request->input('sort', ''))))
9997
->normalize()
10098
->hydrateDefinition($repository, $request)
@@ -103,13 +101,13 @@ public static function collectSorts(RestifyRequest $request, Repository $reposit
103101
->hydrateRepository($repository);
104102

105103
// Merge field sorts with request sorts and ensure it stays a SortCollection
106-
return new SortCollection($requestSorts->merge($fieldSorts));
104+
return new SortCollection($requestSorts);
107105
}
108106

109107
public static function collectFieldSorts(RestifyRequest $request, Repository $repository): Collection
110108
{
111109
return $repository->collectFields($request)
112-
->filter(fn (Field $field) => $field->isSortable($request))
110+
->filter(fn(Field $field) => $field->isSortable($request))
113111
->map(function (Field $field) {
114112
$sortableFilter = new SortableFilter;
115113
$sortableFilter->setColumn($field->getAttribute());
@@ -148,7 +146,7 @@ public static function collectSearchables(RestifyRequest $request, Repository $r
148146
public static function collectFieldSearchables(RestifyRequest $request, Repository $repository): Collection
149147
{
150148
return $repository->collectFields($request)
151-
->filter(fn (Field $field) => $field->isSearchable($request))
149+
->filter(fn(Field $field) => $field->isSearchable($request))
152150
->map(function (Field $field) use ($request, $repository) {
153151
$searchColumn = $field->getSearchColumn($request);
154152
if ($searchColumn instanceof SearchableFilter) {
@@ -197,7 +195,7 @@ public static function collectMatches(RestifyRequest $request, Repository $repos
197195
public static function collectFieldMatches(RestifyRequest $request, Repository $repository): Collection
198196
{
199197
return $repository->collectFields($request)
200-
->filter(fn (Field $field) => $field->isMatchable($request))
198+
->filter(fn(Field $field) => $field->isMatchable($request))
201199
->map(callback: function (Field $field) use ($request) {
202200
$matchColumn = $field->getMatchColumn($request);
203201
if ($matchColumn instanceof MatchFilter) {
@@ -249,7 +247,7 @@ public static function collectFilters($type): Collection
249247
}
250248

251249
return $type instanceof Filter
252-
? tap($type, fn ($filter) => $filter->column = $filter->column ?? $column)
250+
? tap($type, fn($filter) => $filter->column = $filter->column ?? $column)
253251
: tap(new $base, function (Filter $filter) use ($column, $type) {
254252
$filter->type = $type ? $type : 'value';
255253
$filter->column = $column;

0 commit comments

Comments
 (0)