LifeOnScreen / nova-sort-relations

This package improves support for sorting relations in Laravel Nova.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible ordering bug

garyross opened this issue · comments

When I repeat ordering I get an error message:
local.ERROR: Order direction must be "asc" or "desc".
The relevant file is
vendor/lifeonscreen/nova-sort-relations/src/SortRelations.php(64).

I think that the $direction variable can be empty which leads to the error message. It tends to happen on the 2nd click. My guess is that Nova sends an empty string on 'asc' (default) ordering and this leads to the issue. I have added a line that gives a simple fix

foreach ($orderings as $column => $direction) {
            $direction = $direction ?: 'asc';       // add this line
            if (array_key_exists($column, $sortRelations)) {
                $query = self::applyRelationOrderings($column, $direction, $query);
            } else {
                $query->orderBy($column, $direction);
            }
        }