我想创建搜索表单,然后通过 View 显示结果。在我提交结果显示在 view searchome 中但是当提交后刷新页面时我得到重新提交我如何通过邮寄路线搜索并防止通过刷新页面重新提交?
public function src_fn(){
$para=Input::get('txt_pro_id');
$result=DB::table('testing_tbl')->where('pro_id','=',$para)->paginate(5);
return View::make('searchome')->with('result',$result);
}
我的搜索 View
<form method="post" action="{{route('findsresult')}}" name="frm_srch" role="search">
{!! csrf_field() !!}
<input type="Text" name="txt_pro_id" id="txt_pro_id">
<input type="Submit" value="OK">
</form>
我的搜索 View
<table cellpadding="10px" width="100%" class="table_str">
<thead style="font-size: 11px;">
<tr>
<th>Pro ID</th>
<th>Pro Name</th>
<th>Pro price</th>
</tr>
</thead>
<tbody style="font-size: 11.5px;">
@foreach($result as $vals)
<tr scope="row" style="border-bottom: solid 1px #ccc">
<td>{{$vals->pro_id}}</td>
<td>{{$vals->pro_name}}</td>
<td>{{$vals->pro_price}}</td>
</tr>
@endforeach
</tbody>
</table>
<?php echo $result->render(); ?>
我的路线
Route::post('findsresult', 'SearchController@src_fn')->name('findsresult');
最佳答案
要销毁发布请求并防止浏览器在刷新后一遍又一遍地重新发送它,您可以使用 Post/Redirect/Get设计模式,为此你可以创建一个新的获取路线:
Route::get('showresults', 'SearchController@src_show_fn')->name('showresults');
然后在 Controller 的 src_fn
中使用重定向调用新的 get 路由:
public function src_fn(){
$para=Input::get('txt_pro_id');
return redirect('showresults')->with('pro_id', $para);
}
在 src_show_fn
方法中:
public function src_show_fn(){
$para = session('pro_id');
$result = DB::table('testing_tbl')->where('pro_id','=',$para)->paginate(5);
return View::make('searchome')->with('result',$result);
}
关于php - 防止在 laravel 中重新提交后路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48057618/