Advertisement
Guest User

Untitled

a guest
Jun 29th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. let textField = $('#searchUser');
  2. textField.on('keyup', function () {
  3.  
  4. const textFieldValue = $(textField).val();
  5.  
  6. if (textFieldValue.length > 3) {
  7.  
  8. $.ajax({
  9. headers: {
  10. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  11. },
  12. dataType: 'json',
  13. type: "POST",
  14. url: '/search',
  15. data: {
  16. 'string': textFieldValue
  17. },
  18. success: function (response) {
  19.  
  20. console.log(response);
  21. console.log(textFieldValue);
  22. }
  23.  
  24.  
  25. });
  26. }
  27.  
  28. });
  29.  
  30.  
  31. /**
  32. * @param Request $request
  33. * @return JsonResponse
  34. */
  35. public function searchUser(Request $request): JsonResponse
  36. {
  37. $string = $request->input('searchUser');
  38.  
  39. $user = DB::table('users')->where('name', 'LIKE','%'. $string.'%')
  40. ->orWhere('surname', 'LIKE','%'. $string.'%')
  41. ->orWhere('phone_number', 'LIKE','%'. $string.'%')
  42. ->orWhere('email', 'LIKE','%'. $string.'%')
  43.  
  44.  
  45. ->get();
  46.  
  47.  
  48. return response()->json([
  49. 'user' => $user,
  50. 'string' => $string,
  51. 'request'=>$request
  52. ]);
  53. }
  54.  
  55. <form method="POST" action="{{ route('admin.search-user') }}">
  56. @csrf
  57.  
  58. <div class="form-group row" id="searchUserForm">
  59. <label for="searchUser"
  60. class="col-md-4 col-form-label text-md-right">{{ __('Wyszukaj użytkownika') }}</label>
  61.  
  62. <div class="col-md-6">
  63.  
  64. <input class="form-control" id="searchUser"
  65. placeholder="Wyszukaj użytkownika..." name="searchUser">
  66. </div>
  67.  
  68. </div>
  69. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement