Laravel live search

Posted 2 years ago by manojvarma

Hi i want to include a live search in a text field. i used ajax for that. I dont have any error but it is not showing any search results. My form is :

<form action="stationary-add-item" method="POST">
  <div class="form-group">
    <input type="text" name="searchname" class="form-control" id="searchname" placeholder="Enter item name">
  </div>
</form>

My controller is :

public function autocomplete(Request $request)
    {
        $term=$request->term;
        $data = stationary::where('item','LIKE','%'.$term.'%')
        ->take(10)
        ->get();
        $results=array();
        foreach ($data as $key => $v){
$result[]=['value' =>$v->item];
        }
        return response()->json($results);
}

route :

Route::get("/autocomplete",array('as'=>'autocomplete','uses'=> '[email protected]'));

Please sign in or create an account to participate in this conversation.