properly handle wrong and default sort arg in dash table list

This commit is contained in:
2018-08-16 22:38:47 +02:00
parent f594ef412e
commit d5f516853d
+9 -1
View File
@@ -20,7 +20,9 @@ class DashController extends Controller
return back();
}
$data['tableSort'] = $sort = \Input::get('tableSort', 'last-updated');
$defaultSort = 'last-updated';
$sort = \Input::get('tableSort', $defaultSort);
$data['sortOptions'] = [
'most-visited' => 'Most Visited',
@@ -34,6 +36,12 @@ class DashController extends Controller
'least-rows' => 'Shortest',
];
if (!in_array($sort, array_keys($data['sortOptions']))) {
$sort = $defaultSort;
}
$data['tableSort'] = $sort;
$data['users'] = User::orderBy('updated_at', 'desc')
->withCount(['tables'])
->paginate(10, ['id', 'title', 'name', 'tables_count'], 'userPage')