Laravel 10: Autocomplete search works ONLY on name field

Hey Guys,

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') }}";
				source: function (term, process) {
					return $.get(route, {
						term: term
					}, function (data) {
						return process(data);

Laravel 10 controller:

 public function autocomplete(Request $request): JsonResponse
    {   $fineWord = $request->get('term');
        $data = User::select('fname')
                    ->where('fname', 'LIKE', '%'. $fineWord . '%')
        return response()->json($data);

Does the User object contain an accessible fname?

also, what does process() do?

Assuming your referring to the model, and yes its confirmed.

Good question, the tutorials are’t very detailed but something to look at…

“the tutorials” means nothing to me.

Hey M_hutley,

I’m still lost as to why typeahead isn’t working. the results hasn’t change other the the field name.

I attached results and images, you can give me some direction

The screenshot from Edge developer tool:.

screenshot of user entry field

sample user entry field:

Using: “name”
[{“name”:“Jarod Kessler”},{“name”:“Delpha Sipes III”},{“name”:“Octavia Borer”},{“name”:“Dr. Ali Koch”},{“name”:“Carrie Waelchi”},{“name”:“Gracie Parker”},{“name”:“Zane Ledner MD”},{“name”:“Miss Maia Rau”},{“name”:“Edgardo Quigley”},{“name”:“Leola Mohr”},{“name”:“Raven Lesch Jr.”},{“name”:“Prof. Maybelle Schulist MD”},{“name”:“Brandyn Keeling”},{“name”:“Carlotta Schoen”}]

Using: “fname”

I cant answer this question without knowing what process() does.

I am sure, you do not add jquery typeahead and bootstrap into your web page. Please it add something like this:

<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <title>Laravel 11 Typeahead Autocomplete Search Example -</title>
  <link href="" rel="stylesheet">
    .container {
      padding: 10%;
      text-align: center;
<div class="container">
    <div class="row">
        <div class="col-12"><h2>Laravel 11 Typeahead Autocomplete Search Example -</h2></div>
        <div class="col-12">
            <div id="custom-search-input">
                <div class="input-group">
                    <input id="search" name="search" type="text" class="form-control" placeholder="Search" />
<script src=""></script>
<script src=""></script>
<script type="text/javascript">
    var route = "{{ url('search-autocomplete') }}";
        source:  function (term, process) {
            return $.get(route, { term: term }, function (data) {
                return process(data);

For more detailed, you can also consider it:

I’m confused. How is your answer:

different from what the user has already got and says doesnt work?

Also how do you say

when your answer contains the lines


sorry it’s was my mistake, please consider the following code for this error.

     public function searchAutocomplete(Request $request)
          $search = $request->get('term');
          $result = User::where('fname', 'LIKE', '%' . $search . '%')->pluck('fname');
          return response()->json($result);