AutoComplete in Laravel

0
Are you guys okay? so I am trying to develop an application in Laravel and it happens that I am putting an AutoComplete but it is not running. Please help me there!

This is the ajax

$(document).ready(function(){
  $('#users').keyup(function () {
      var q=$(this).val();
      if(word.length>3) {

          $.ajax
          ({
              type: "GET",
              url: "/User/Dados",
              data: {q:q},
              contentType: "json",
              cache: false,
              success: function(data, status, xhr)
              {
                  $('#users').val(data[0].value);
              }
          });
      }
  });

This is the html

<i class="material-icons prefix">textsms</i>
      <input type="text" id="users" class="autocomplete">
      <label for="autocomplete-input">Pesquisar</label>

This is the Route

Route::get('/User/Dados','User\UserController@buscar');

And finishing this here is the Controller

public function buscar(Request $req){

  $user_date = $req->all();
  $users = User::all();
  $result = [];

  foreach ($users as $user) {
          $result[] = $user['name'];
  }
  return response()->json($result);}

Thank you!

    
asked by anonymous 25.05.2018 / 17:51

0 answers