2017-06-05 46 views
2

嗨,我正在關注如何設置搜索表單的教程,但我得到一個route錯誤(NotFoundHttpException)。Laravel搜索表單中的無效路由

形式

{!! 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() !!} 

路線

URL(瀏覽器)

http://localhost:8000/search?_token=LJpgN3AwCFoDElOkFsSOX8BBLU1IFOzMvUYiokQj&utf8=%E2%9C%93&searchKey=quia 

回答

2

你的路線改成這樣。當您將搜索參數作爲查詢字符串傳遞時,不需要url的第二部分。

Route::get('search', '[email protected]')->name('search'); 

將您的表單更改爲此。當您使用表單GET方法時,您不需要發送csrf標記。

{!! 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() !!} 

我也刪除了不需要的輸入<input name="utf8" type="hidden" value="✓">。如果是有意的,請將其添加回來。