{{ $members->appends(request()->only(['country']))->links() }}
Mar 28, 2017
6
Level 6
pagination with filtering - issue in pagination goes back to unfiltered data
Hi all,
I want to show all records in index.blade.php, at the same time I wan to allow users to filter results based in certain criteria such as country etc.
I was able to implement filter and pagination but I have once issue :
When the user filter something , pagination does not pick the filtered result except in page #1. Then it will go back to unfiltered data,
here is the code in controller
public function index(Request $request) {
if ($request->has('country') ) {
$members = Member::where('country',$request->country)->paginate(5);
} else {
$members = Member::paginate(8) ;
}
return view('members.index', compact('members'));
}
in index.blade.php .. the code to send filtered info is :
form method="get" action="/members">
<input type="checkbox" name="country" value="Oman"/> Oman <br>
<input type="submit" class="btn btn-default" value="Filter">
</form>
please advice how can I keep the pagination linked to filtered data
Level 13
{{ $members->appends(request()->only(['country','state','region'.....]))->links() }}
Please or to participate in this conversation.