SHARE
TWEET

Untitled

a guest Mar 21st, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {{ Form::open(['route' => 'admin.users.search', 'method' => 'get', 'class' => 'navbar-form navbar-left form-inline', 'role' => 'search']) }}
  2.  
  3. <div class="form-group">
  4.     {{ Form::text('user_id', request('user_id'), ['class' => 'form-control', 'size' => '8', 'placeholder' => 'ID']) }}
  5. </div>
  6.  
  7.  
  8. <div class="form-group">
  9.     {{ Form::email('email', request('email'), ['class' => 'form-control', 'size' => '20', 'placeholder' => 'Email']) }}
  10. </div>
  11.  
  12. <div class="form-group">
  13.     {{ Form::text('first_name', request('first_name'), ['class' => 'form-control', 'size' => '20', 'placeholder' => 'First Name']) }}
  14. </div>
  15.  
  16. <div class="form-group">
  17.     {{ Form::text('family_name', request('family_name'), ['class' => 'form-control', 'size' => '20', 'placeholder' => 'Family Name']) }}
  18. </div>
  19.  
  20. <div class="form-group">
  21.     <div class="selectize-lg">
  22.         {{ Form::select('institution_id', $institutions, request('institution_id'), ['class' => 'form-control', 'size' => '200', 'data-selectize']) }}
  23.     </div>
  24. </div>
  25.  
  26. <div class="form-group">
  27.     <div class="selectize-lg">
  28.         {{ Form::select('exam_id', $exams, request('exam_id'), ['class' => 'form-control', 'data-selectize']) }}
  29.     </div>
  30. </div>
  31.  
  32. <div class="form-group  ">
  33.     {{ Form::submit('Search', ['class' => 'btn btn-default']) }}
  34. </div>
  35.  
  36. <a href="{{ route('admin.users.index') }}" class="btn btn-warning">Clear</a>
  37.  
  38. {{ Form::close() }}
  39.    
  40. Route::get('members/search', 'UsersController@search')->name('admin.users.search');
  41.    
  42. $users = User::with('exam', 'institution');
  43.  
  44.  
  45.     if ($request->has('user_id')) {
  46.         $users->whereId($request->user_id);
  47.     }
  48.  
  49.     if ($request->has('email')) {
  50.         $users->whereEmail($request->email);
  51.     }
  52.  
  53.     if ($request->has('first_name')) {
  54.         $users->where('first_name', 'LIKE', "%{$request->first_name}%");
  55.     }
  56.  
  57.     if ($request->has('family_name')) {
  58.         $users->where('family_name', 'LIKE', "%{$request->family_name}%");
  59.     }
  60.  
  61.     if ($request->has('institution_id')) {
  62.         $users->whereInstitutionId($request->institution_id);
  63.     }
  64.  
  65.     if ($request->has('exam_id')) {
  66.         $users->whereExamId($request->exam_id);
  67.     }
  68.  
  69.     $users = $users->latest()->paginate(48);
  70.     $usersTotal = $users->total();
  71.  
  72.     $exams = ['' => 'Exam...'] + Exam::orderBy('title')
  73.         ->pluck('title', 'id')
  74.         ->all();
  75.  
  76.     $institutions = ['' => 'University...'] + Institution::orderBy('name')
  77.         ->pluck('name', 'id')
  78.         ->all();
  79.  
  80.     return view('admin.users.index', compact('users', 'usersTotal', 'exams', 'institutions'));
  81.    
  82. {{ $users->appends(array_filter(request()->except('page')))->render() }}
  83.    
  84. search?user_id=&email=hello%40world&first_name=John&family_name=Smith&institution_id=1&exam_id=1
  85.    
  86. search?page=2
RAW Paste Data
Top