Typeahead search for integer value

  javascript, laravel

I am using a typeahead search for filtering suggestions from database. It works well for column ‘name’ but when I tried to get integer value or primary key column (having string value), there is no response.

On the other side, the same code for other string columns works well.

function autoComplete(Request $request){
    $roll_number =  student::select('roll_number')
    ->where('roll_number','LIKE','%'.$request->get('query').'%')->get();
   return response()->json($roll_number);
}

where roll_number is a primary key column with a string datatype. If I search name instead of roll_number, it works fine.

<script>
  var path = "{{URL('autoComplete')}}";
  $('#search.typeahead').typeahead({
    source: function (query, process) {
    return $.get(path, {query: query}, function (data){
             return process(data);
          });
    }
  });
</script>

Source: Laravel

Leave a Reply