diff --git a/framework/core/src/Flarum/Api/Actions/Base.php b/framework/core/src/Flarum/Api/Actions/Base.php index 897425488..53a765e91 100644 --- a/framework/core/src/Flarum/Api/Actions/Base.php +++ b/framework/core/src/Flarum/Api/Actions/Base.php @@ -104,16 +104,19 @@ abstract class Base extends Controller protected function sort($options) { $criteria = (string) $this->input('sort', ''); + $order = null; + + if ($criteria && $criteria[0] == '-') { + $order = 'desc'; + $criteria = substr($criteria, 1); + } if (! in_array($criteria, $options)) { $criteria = reset($options); } - $order = $criteria ? 'asc' : null; - - if ($criteria && $criteria[0] == '-') { - $order = 'desc'; - $criteria = substr($criteria, 1); + if ($criteria && ! $order) { + $order = 'asc'; } return [