Various messy code.

This commit is contained in:
James Cole
2024-05-10 09:17:09 +02:00
parent 794e31e487
commit aa5c4c20e9
10 changed files with 170 additions and 45 deletions

View File

@@ -28,8 +28,11 @@ use LaravelJsonApi\Core\Query\SortFields;
trait SortsCollection
{
protected function sortCollection(Collection $collection, SortFields $sortFields): Collection {
protected function sortCollection(Collection $collection, ?SortFields $sortFields): Collection {
if(null === $sortFields) {
return $collection;
}
foreach($sortFields->all() as $sortField) {
$collection = $sortField->isAscending() ? $collection->sortBy($sortField->name()) : $collection->sortByDesc($sortField->name());
}