/** * Display All the users * @param User $UserModel The user model * @return \Illuminate\View\View the users index view index.blade.php */ public function index(User $UserModel, Request $req) { // get an instance of the user model and order the query by id desc $users = $UserModel->admin()->orderBy('id', 'desc'); // if theres any variables sent throught the request we use them as where arguments if ($req->has('email')) { $users->where('email', $req->input('email')); } if ($req->has('sex')) { $users->where('sex', $req->input('sex')); } // get our results with pagination with 20 user per page $users = $users->paginate(20); // return the index view of the users module with a collection of users objects return view('users::users.index', compact('users')); }