From 5bc4bff8f9cfa8d7e47aaed266815b1be02f8bab Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Sun, 9 Feb 2020 00:32:39 +0800 Subject: [PATCH] add sorter --- app/Http/Controllers/Admin/UserController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 65fff590..114f4634 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -15,10 +15,14 @@ class UserController extends Controller { $current = $request->input('current') ? $request->input('current') : 1; $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; + $sortType = $request->input('sort_type') ? 'ASC' : 'DESC'; $userModel = User::orderBy('created_at', 'DESC'); if ($request->input('email')) { $userModel->where('email', $request->input('email')); } + if ($request->input('sort')) { + $userModel->orderBy($request->input('sort'), $sortType); + } $total = $userModel->count(); $res = $userModel->forPage($current, $pageSize) ->get();