2

Hi i'm following a tutorial bout how to set a search form but I'm getting a route error (NotFoundHttpException).

form

   {!! Form::open(['method'=>'GET' ,'url' => 'search', 'class'=>'form-group main-form', 'id'=>'search-form', 'role'=>'form']) !!}
      {{ csrf_field() }}
      <div style="display:none"><input name="utf8" type="hidden" value="✓"></div>
      <input class="form-group main-form" id="q_objname_en_cont" name="searchKey"  placeholder='Search by Job title' required="required" style="height:40px;width:60%" type="search">
      <input class="btn btn-warning" type="submit" value="Search">
   {!! Form::close() !!}

Route

//Search route(get)
Route::get('search/{searchkey}', 'EmploiController@search')->where('searchkey', '[A-Za-z]+')->name('search');

url (browser)

http://localhost:8000/search?_token=LJpgN3AwCFoDElOkFsSOX8BBLU1IFOzMvUYiokQj&utf8=%E2%9C%93&searchKey=quia
Papouche Guinslyzinho
  • 5,277
  • 14
  • 58
  • 101

2 Answers2

2

Change your route to this. You don't need the second part of url when you're passing the search parameters as the query string.

Route::get('search', 'EmploiController@search')->name('search');

Change your form to this. You don't need to send the csrf token when you're using form GET method.

{!! Form::open(['method'=>'GET' ,'url' => 'search', 'class'=>'form-group main-form', 'id'=>'search-form', 'role'=>'form']) !!}
<input class="form-group main-form" id="q_objname_en_cont" name="searchKey"  placeholder='Search by Job title' required="required" style="height:40px;width:60%" type="search">
<input class="btn btn-warning" type="submit" value="Search">
{!! Form::close() !!}

I've also removed the unwanted input <input name="utf8" type="hidden" value="✓">. Add it back if it was intended.

Sandeesh
  • 11,486
  • 3
  • 31
  • 42
0

I think everything is wrong with the tutorial you're following, there are not security concerns, and certainly, that is not the proper way to implement a search in Laravel, you are exposing your csrf_token to the world in every request to that route.

My advice for you is to read better resources and take a deep dive into the docs.

https://laracasts.com/discuss/channels/laravel/search-option-in-laravel-5?page=1