Using laravel and jquery for input field autocomplete. I need to select name and store the id of that user in input field.
<input id="show-user" type="text" class="typeahead form-control" name="student_code" value="{{ old('student_code') }}" placeholder="Student Code" required>
Here is javascript code
var path = "{{ url('library/issue-books/autocomplete/') }}";
$('input.typeahead').typeahead({
source: function (query, process) {
return $.get(path, { query: query }, function (data) {
return process(data);
});
}
});
Controller code for ptah
$data = User::where("name","LIKE","%{$request->input('query')}%")->get();
return response()->json($data);
Now my problem is when I select name, need to send student code in request. Student_code integer column.
You can send the input value to your route:
In this way you should have this route syntax:
But you can pass just a query string also: