表单清除给定操作网址中的参数-PHP Laravel

时间:2018-08-14 13:06:25

标签: php html laravel

<form role="search" method="get" action="{{ route('people.search', array_replace(Request::all(), [" type" => "customers"])) }}">
<div class="input-group">
    <input type="text" name="search" class="form-control" placeholder="Search...">
    <div class="input-group-btn">
        <button class="btn btn-primary"><i class="fa fa-search"></i></button>
    </div>
</div>
</form>

以下表单操作链接如下所示:

http://127.0.0.1:8080/people/search/customers?countries=Germany&statuses=3&page=1

但是当我提交搜索表单时,它会重定向到:

http://127.0.0.1:8080/people/search/customers?search=test

而不是包括先前设置的参数。

有办法防止这种情况吗?

1 个答案:

答案 0 :(得分:0)

我要做的包括上一个参数只是将它们添加为隐藏字段:

@foreach(request()->query() as $key => $value)
    @if($key == "page") // Don't want the page parameter to be in there
        @continue
    @endif
    <input type="hidden" name="{{$key}}" value="{{$value}}">
@endforeach