Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
Laralvel autocomplete input from database

Hello im learning Laravel and trying to make an autocompletion of search with sugestion from a database. I see a lot of people doing it with JQuery so that is what i've tried. But when i run the site, i only get one letter of suggestion, and sometimes no suggestion at all. I suspekt my routing is off so i tried dd some information in the query function, but that doesnt show up either,

MY BLADE

   <!DOCTYPE html>
<html>
<head>
    <title>Laravel 8 Autocomplete Search using Bootstrap Typeahead JS -ItSolutionStuff.com</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>
</head>
<body>
   
<div class="container">
    <h1>Laravel 8 Autocomplete Search using Bootstrap Typeahead JS - ItSolutionStuff.com</h1>   
    <input class="typeahead form-control" type="text">
</div>
   
<script type="text/javascript">
    var path = "{{ route('autocomplete') }}";
    $('input.typeahead').typeahead({
        source:  function (query, process) {
        return $.get(path, { query: query }, function (data) {
                return process(data);
            });
        }
    });
</script>
   
</body>
</html>

MY CONTROLLER

    class TypeaheadController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('welcome');
    }
  
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function autocomplete(Request $request)
    {
        dd('h');
        $data = Edit::select("Adresse")
                ->where("Adresse","LIKE","%{$request->query}%")
                ->get();
   
        return response()->json($data);
    }
}

MY Routing

Route::get('search', [TypeaheadController::class, 'index'])->name('search');
Route::get('autocomplete', [TypeaheadController::class, 'autocomplete'])->name('autocomplete');

If you guys have any other suggestion on how i can do it. feel free to suggest

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

$request->query is a reserved function on the $request object. in order to pull the '?query=xyz' from the url in the request you would have to use the $request->query('query') function to return xyz.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda