500 Internal Server Error on Laravel 8 Typeahead

292 Views Asked by At

So, I tried to implement an autocomplete search on Laravel 8 with Typeahead and jquery, but it gives me 500 (internal server error), I wonder what is wrong with my codes?

<div class="container">
    <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>

Search Controller :

 public function autocomplete(Request $request){
        $query = $request->query;
        $data = Item::select("name")
            ->where("name","LIKE","%{$request->query}%")
            ->get();
        return response()->json($data);
    }
0

There are 0 best solutions below