add sorter

This commit is contained in:
Tokumeikoi 2020-02-09 00:32:39 +08:00
parent ab97db552d
commit 5bc4bff8f9

View File

@ -15,10 +15,14 @@ class UserController extends Controller
{ {
$current = $request->input('current') ? $request->input('current') : 1; $current = $request->input('current') ? $request->input('current') : 1;
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
$sortType = $request->input('sort_type') ? 'ASC' : 'DESC';
$userModel = User::orderBy('created_at', 'DESC'); $userModel = User::orderBy('created_at', 'DESC');
if ($request->input('email')) { if ($request->input('email')) {
$userModel->where('email', $request->input('email')); $userModel->where('email', $request->input('email'));
} }
if ($request->input('sort')) {
$userModel->orderBy($request->input('sort'), $sortType);
}
$total = $userModel->count(); $total = $userModel->count();
$res = $userModel->forPage($current, $pageSize) $res = $userModel->forPage($current, $pageSize)
->get(); ->get();