So I'm having a problem with appending the query string to the results, I have simple filtering (select/dropdown) in my form and a search box (input).
The problem is the result of the steps below:
-
IF I do select an item in the dropdown and then;
-
Type to search input, and press the SUBMIT button, the query string from the dropdown is removed and only the query string from the search is appended to the URL.
Example URL after doing the step above:
http://example.test/users?search=bar
The final URL should be:
http://example.test/users?filter=foo&search=bar
The HTML form
<a href="{{ route('users', [
'filter' => 1,
'search' => request()->get('search')
]) }}">
Filter #1
</a>
<a href="{{ route('users', [
'filter' => 2,
'search' => request()->get('search')
]) }}">
Filter #2
</a>
<form action="{{ route('users', [
'filter' => request()->get('filter'),
'search' => request()->get('search')
]) }}" method="GET">
<input type="text" name="search" value="{{ request()->get('search') }}">
<button type="submit"></button>
</form>
Controller
public function users(Request $request) {
$users = User::query()
->where('filter', $request->get('filter'))
->where('name', 'like', '%'.$request->get('search').'%')
->paginate(10);
$users->appends([
'search' => $request->get('search'),
'filter' => $request->get('filter')
]);
}
I also tried appending ->withQueryString() after paginate(10) but it's still not doing the trick.
I don't know why the filter query string is not appended after submitting the search form.