Autocomplete no Laravel

Asked

Viewed 708 times

0

Eae guys td well? so I’m trying to develop an application in Laravel and I happen to be putting an Autocomplete but it’s not running. Please help me out there!

This here 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 one is html

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

This here is the Route

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

And finishing this one 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);}

inserir a descrição da imagem aqui

Thank you Guys!

  • Would not be if(q.length > 3) instead of if(word.lenght > 3) exchange the word by q in if?

  • Dude, you still haven’t done anything =(

  • Give a console.log( data ) to see what displays

  • Also change the keyup this one $('#users').on('keyup',function ()

  • yes, I had already changed

  • I’ll check the console

  • From what I’ve seen, you want to check everything in the User table when typing, that’s right?

  • yes, I’m willing to do this

  • After you switched the word to q you cleared the cache?

  • yes, I cleaned up all the cache and it still looks like this

  • you tested? or something like that?

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.