2017-06-05 50 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="✓">。如果是有意的,请将其添加回来。