title: Autocomplete search in Laravel
body: <p>I was wondering if there is any way I can display more than one fields in the autocomplete search box. It already search for fist and last name but when the user types the last name it shows only the first name. But I wonder if there is a way that I can also display the last name or address on the search result. I am only getting the id of the guardian because it's the only thing I need to sent to the database. Here is a look at my code:</p>
  
  <p>This is my function for the autocomplete:</p>
  
  <pre><code>public function autocomplete(Request $request)
      {
          $term=$request-&gt;term;
          $data = Guardian::orWhere('first_name','LIKE','%'.$term.'%')
          -&gt;orWhere('last_name','LIKE','%'.$term.'%')
          -&gt;take(10)-&gt;get();
          $results=array();
          foreach($data as $key =&gt; $v)
          {
              $results[]=['id'=&gt;$v-&gt;idguardian, 'value'=&gt;$v-&gt;first_name];
          }
          return response()-&gt;json($results);
      }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>  &lt;div class="row"&gt;
      &lt;div class="col-md-6"&gt;
        &lt;h3&gt;New Kid&lt;/h3&gt;
        &lt;p&gt; Please search the guardian name for the kid. If the guardian isn't registered please add it&lt;/p&gt;
        &lt;form action="{{route('createkid')}}" method="post"&gt;
        &lt;div class="form-group"&gt;
            &lt;input type="text" name="searchname" class="form-control" id="searchname" placeholder="Search"&gt;
            &lt;tr&gt;
              &lt;td&gt;ID&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="idguardian" id="idguardian" class="form-control"&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
            &lt;/tr&gt;
      &lt;/div&gt;
          &lt;a href="{{URL::to('addguardian/list/')}}" class="btn btn-success btn-xs" &gt;Add Guardian&lt;/a&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="first_name"&gt;First Name&lt;/label&gt;
          &lt;input type="text" name="first_name" class="form-control" placeholder="FirstName"&gt;
        &lt;/div&gt;   
        &lt;div class ="form-group"&gt;
          &lt;label for="middle_name"&gt;Middle Name&lt;/label&gt;
          &lt;input type="text" name="middle_name" class="form-control" placeholder="MiddleName"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="last_name"&gt;Last Name&lt;/label&gt;
          &lt;input type="text" name="last_name" class="form-control" placeholder="LastName"&gt;
        &lt;/div&gt;
          &lt;div class ="form-group"&gt;
          &lt;label for="dateofbirth"&gt;Date Of Birth&lt;/label&gt;
          &lt;input type="text" name="dateofbirth" class="form-control" placeholder="DateOfBirth"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="sex"&gt;Sex&lt;/label&gt;
          &lt;input type="text" name="sex" class="form-control" placeholder="Sex"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="age"&gt;Age&lt;/label&gt;
          &lt;input type="text" name="age" class="form-control" placeholder="Age"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="schoolname"&gt;School Name&lt;/label&gt;
          &lt;input type="text" name="schoolname" class="form-control" placeholder="SchoolName"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="schoolgrade"&gt;School Grade&lt;/label&gt;
          &lt;input type="text" name="schoolgrade" class="form-control" placeholder="SchoolGrade"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="schoolgroup"&gt;School Group&lt;/label&gt;
          &lt;input type="text" name="schoolgroup" class="form-control" placeholder="SchoolGroup"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="bloodtype"&gt;Blood Type&lt;/label&gt;
          &lt;input type="text" name="bloodtype" class="form-control" placeholder="BloodType"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="allergies"&gt;Allergies&lt;/label&gt;
          &lt;input type="text" name="allergies" class="form-control" placeholder="Allergies"&gt;
        &lt;/div&gt;
        &lt;div class ="form-group"&gt;
          &lt;label for="enroll_date"&gt;Enroll Date&lt;/label&gt;
          &lt;input type="text" name="enroll_date" class="form-control" placeholder="EnrollDate"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          {!! Form::label('iduser','Select User') !!}
          {!! Form::select('iduser', $kids, ['class' =&gt; 'form-control']) !!}
        &lt;/div&gt;
  
        &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
        &lt;input type="hidden" name="_token" value="{{ Session::token()}}"&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;script type="text/javascript"&gt;
  $("#searchname").autocomplete({
    source : '{!!URL::route('autocomplete')!!}',
    minLenght:1,
    autoFocus:true,
    select:function(e, ui){
      $('#idguardian').val(ui.item.id);
  
    }
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>My Route:</p>
  
  <pre><code>Route::get('/autocomplete',array('as'=&gt;'autocomplete','uses'=&gt;'KidsController@autocomplete'));
  </code></pre>
  
  <p>I really hope you can help me. Thank you!</p>