usamafiaz's avatar

pagination with search filter

how to create filter pagination when input in search field tag

0 likes
4 replies
talel's avatar

I think what are you looking for is a way to add a query based on the search tag and then paginate?

$users = User::where('tag', $tag)->paginate(15);

What @a4ashraf suggested is a great way to create an endpoint that will have the query string value already appended, useful when needed to be able to share a link for those results.

Neeraj1005's avatar

@usamafiaz Can you show your controller method what query you have executed..?

In your controller if you have query like this

$users = User::search(request('search_input'))->paginate(15);

then appendwithQueryString() after paginate.

$users = User::search(request('search_input'))->paginate(15)->withQueryString();
usamafiaz's avatar

---ruby controller use WithPagination; public function index(Request $request) { if($request->search ){ $search = '%'.$request->search.'%'; $students = student::where('first_name','LIKE',$search)->paginate(5)->withQueryString(); return view('admin.pagination.pagination')->with('students', $students); }else{ return view('admin.pagination.pagination')->with('students', student::paginate(5)); } }

Please or to participate in this conversation.