php - 防止在 laravel 中重新提交后路由

标签 php laravel laravel-5 laravel-5.3

我想创建搜索表单,然后通过 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/

相关文章:

php - 使用 cvs 在 webapp 上作为一个组工作

php - 如何使用codeigniter将csv文件导入mysql

php - Laravel 5 更新返回旧关系

Laravel 5.5 使用自定义消息进行验证

php - Laravel:在子数组中嵌套查询连接结果

php - 检查酒店房间的可用性

php - 如何显示所选年份的两个不同列

php - 如何在 Laravel 中验证时间

php - 具有 Eloquent 关系的空对象模式

php - 如何编写迁移以撤消 Laravel 中的唯一约束?