properly handle wrong and default sort arg in dash table list

master
Ondřej Hruška 6 years ago
parent f594ef412e
commit d5f516853d
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 10
      app/Http/Controllers/DashController.php

@ -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')

Loading…
Cancel
Save