I found a tutorial on how to create a “autocomplete” field but the tutorial only focuses on searching the “name” field. name field is the generic database table field created by laravel 10 default installation.
Problem: when I change the search criteria from “name” to “fname” or “lname” field it fails to produce any results and nothing seems to appear. On the other hand if I changed the search criteria back to “name” field it works!
Laravel 10
confirmed both field names: fname, lname
What am I missing???
User entry form:
<input class="typeahead form-control" id="search" name="search" type="text">
<script type="text/javascript">
var route = "{{ route('autocomplete') }}";
$('#search').typeahead({
source: function (term, process) {
return $.get(route, {
term: term
}, function (data) {
return process(data);
});
}
});
</script>
Hey! If your autocomplete works with "name" but not with “fname” or “lname,” it’s likely due to a mismatch in the field names or the data types in your database. Double-check that “fname” and “lname” exist in your database schema and are correctly populated with data. Also, verify your search query syntax, ensuring it accurately queries these fields. Additionally, inspect any frontend code or JavaScript to ensure it’s referencing the right fields. Finally, clear your Laravel cache with php artisan cache:clear and rebuild your application to see if that resolves the issue.