You have user, not users.
Feb 4, 2021
8
Level 2
Laravel 8 Pagination using withQueryString() not working as expected
I have this in a model
//Doing a post request and passing a name $searchName = $request->input('name');
//To simplify the issue I am just pulling all users. $user = User::paginate(5)->withQueryString();
return view('dashboard', ['users' => $user]);
In my view i have this for the pagination links. I assume per the docs the withQueryString would add the name I sent in the post. It does not. {{ $user->links() }}
If I use the appends method it adds the name to the pagination links. $user->appends(['name' => 'bobby.hill']);
Any ideas as to why withQueryString() isn't working?
Level 75
But you use POST request.
Better if you change form to GET request and route as well.
Then withQueryString will work.
Route::get('users', 'YourController')->name('users.index');
<form action="{{ route('users.index') }}" method="GET">
<input type="text" name="name">
<button type="submit">Search</button>
</form>
Please or to participate in this conversation.