laravel 5 : Autocomplete Search
<p>I'm trying to make a autocomplete search in my laravel application. But I'm facing a error while I search for the keyword. I got the following error while i see in console :</p>

<pre><code>http://localhost/autocomplete?term=a 404 (Not Found)
</code></pre>

<p>Here is the route I have used:</p>

<pre><code>Route::get('/autocomplete',[
        'uses'=&gt;'UserController@autocomplete',
        'as'=&gt;'autocomplete'
        ]);
</code></pre>

<p>Here is the controller:</p>

<pre><code>public function autocomplete(Request $request)
{
  $results=array();
    $item = $request-&gt;input(['searchname']);
    $data=User::where('name','LIKE','%' .$item.'%')
    -&gt;take(5)
    -&gt;get();
    foreach ($data as $data) {
      $results[]=['id'=&gt;$data-&gt;id,'value'=&gt;$data-&gt;name];
    }
return response()-&gt;json($results);
}
</code></pre>

<p>And here is the view page with the javascript code:</p>

<pre><code>&lt;div class="ui-widget"&gt;
    &lt;input type="text" name="searchname" id="searchname" placeholder="Search" class="form-control"&gt;
  &lt;/div&gt;

 &lt;script&gt;
   jQuery(document).ready(function($) {
      $('#searchname').autocomplete({
            source:  "/autocomplete" ,
            minlength:1,
            autofocus:true,
            select:function(event,ui){
              $("searchname").val(ui.item.value);
            }
      });
   });
    &lt;/script&gt;
</code></pre>

<p>If anyone find what's the error, try to provide the solution please.Thanks in Advance! </p>