From 7b9c65b5bc234a54dc45749537b845abeae2760d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 6 Feb 2015 12:20:58 +1030 Subject: [PATCH] Fix up API default sort order --- framework/core/src/Flarum/Api/Actions/Base.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Flarum/Api/Actions/Base.php b/framework/core/src/Flarum/Api/Actions/Base.php index df43dc5d4..897425488 100644 --- a/framework/core/src/Flarum/Api/Actions/Base.php +++ b/framework/core/src/Flarum/Api/Actions/Base.php @@ -104,6 +104,11 @@ abstract class Base extends Controller protected function sort($options) { $criteria = (string) $this->input('sort', ''); + + if (! in_array($criteria, $options)) { + $criteria = reset($options); + } + $order = $criteria ? 'asc' : null; if ($criteria && $criteria[0] == '-') { @@ -111,10 +116,6 @@ abstract class Base extends Controller $criteria = substr($criteria, 1); } - if (! in_array($criteria, $options)) { - $criteria = reset($options); - } - return [ 'by' => $criteria, 'order' => $order,