Add ability to filter user list

This commit is contained in:
Dane Everitt 2016-12-02 18:41:52 -05:00
parent ed5b7559ec
commit 3cd0a8337f
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 35 additions and 1 deletions

View file

@ -51,8 +51,33 @@ class UserController extends Controller
public function getIndex(Request $request)
{
$query = User::select('users.*');
if ($request->input('filter') && !is_null($request->input('filter'))) {
preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches);
foreach($matches[0] as $match) {
$match = str_replace('"', '', $match);
if (strpos($match, ':')) {
list($field, $term) = explode(':', $match);
$query->orWhere($field, 'LIKE', '%' . $term . '%');
} else {
$query->where('email', 'LIKE', '%' . $match . '%');
$query->orWhere([
['uuid', 'LIKE', '%' . $match . '%'],
['root_admin', 'LIKE', '%' . $match . '%']
]);
}
}
}
try {
$users = $query->paginate(20);
} catch (\Exception $ex) {
Alert::warning('There was an error with the search parameters provided.');
$users = User::all()->paginate(20);
}
return view('admin.users.index', [
'users' => User::paginate(20)
'users' => $users
]);
}