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!