title: Routes and window.location - Laravel
body: <p>I have a search field with the same name and id inside my categories page and inside my products page.The autocomplete suggestions seems to work fine , however once I click  on search suggestion inside my search field it converts my search string to integer which is my products id .Afterwards its redirecting me to "mysite/products id"  with "No content for this menu" . I guess the issue is with my routes and my window.location inside my JS , but I cant figure it out.</p>
  
  <p>Here is my code </p>
  
  <p>My routes </p>
  
  <pre><code>Route::get('products/{id}', 'AutoCompleteController@show');
      Route::get('autocomplete',array('as'=&gt;'autocomplete','uses'=&gt;'AutoCompleteController@show'));
      Route::get('searchajax',array('as'=&gt;'searchajax','uses'=&gt;'AutoCompleteController@autoComplete'));   
  </code></pre>
  
  <p>Few more routes connected to Categories and Products : </p>
  
  <pre><code>Route::get('shop', 'ShopController@categories');// my categories page
  
  Route::get('shop/{category_url}', 'ShopController@products');  // my products page 
  </code></pre>
  
  <p>My AutoCompleteController: </p>
  
  <pre><code>  &lt;?php
  
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
  use App\Http\Controllers\Controller;
  use App\Product;
  class AutoCompleteController extends MainController {
  
       public function show(Product $product) {
          return view('content.products', ['product' =&gt; $product]);
  
     }
      public function autoComplete(Request $request) {
          $query = $request-&gt;get('term','');
  
          $products=Product::where('title','LIKE','%'.$query.'%')-&gt;get();
  
          $data=array();
          foreach ($products as $product) {
                    $data[]=array('label'=&gt;$product-&gt;title,'value'=&gt;$product-&gt;id);
          }
          if(count($data)){
          return $data;}
          else{
              return ['value'=&gt;'No Result Found','id'=&gt;''];
      }}
  
  } 
  </code></pre>
  
  <p>My view in products.blade and categories.blade for my autocomplete search is the same :</p>
  
  <pre><code>@extends ('master') 
  
  @section('content')   
  &lt;link href="http://demo.expertphp.in/css/jquery.ui.autocomplete.css" rel="stylesheet"&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"&gt;&lt;/script&gt; 
  
  &lt;div class="row"&gt;  
      &lt;form class="navbar-form text-center " form method="GET" action=" "&gt;
          &lt;input id="search_text" placeholder=" Search products" name="search_text" type="text" value="" style="width: 400px; height: 35px; border-radius: 5px ; padding-left: 12px;"&gt;&lt;br&gt;&lt;br&gt;
          &lt;input class="btn btn-default " type="submit" value="  Search" &gt;  
      &lt;/form&gt;
  &lt;/div&gt;
  
  
  &lt;script&gt; 
        $(document).ready(function () {
          src = "{{ route('searchajax') }}";
  $("#search_text").autocomplete({ 
  
      source: function (request, response) {
          $.ajax({
              url: src,
              dataType: "json",
              data: {
                  term: request.term
              },
              success: function (data) {
                  response(data);
  
              }
          });
      },
      minLength: 3,
      select: function( event, ui ) {
  
          window.location = '{{ url('shop/{category_url}')}}' + ui.item.value
      } // not sure if this is the correct way , please advise
  });  
        });
  &lt;/script&gt;
  </code></pre>