Friday, March 17, 2017

Typeahead js Autocompletion Laravel

I try to make an autocompletion search to my laravel application , but i get an error when i inspect my browser i get " b.toLowerCase is not a function "

Here my controller for Autocomplete :

public function autocomplete(Request $request){

        $data = Licencies::select("lb_nom")->where("lb_nom","LIKE","%{$request->input('query')}%")->get();
        return response()->json($data);

    }

Here my view Input :

@section('content')

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <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>

 <input class="typeahead form-control" style="margin:0px auto;width:300px;" type="text">

Here my script :

<script type="text/javascript">
        var path = "";
        $('input.typeahead').typeahead({
            source:  function (query, process) {
                return $.get(path, { query: query }, function (data) {
                    return process(data);
                });
            }
        });
    </script>

Someone knows why i get

b.toLowerCase is not a function

Many thanks in advance



via Mathieu Mourareau

Advertisement