Use like see https://laracasts.com/discuss/channels/eloquent/search-columns-using-like
And paginate as needed.
I'm working on a search function on a website where users can search for other users based on filters like genders, areas, etc. I face several difficulties when coding:
I cannot seem to figure out how to combine pagination with the collection, I get back. I make us of https://github.com/spatie/laravel-paginateroute for pagination. The problem is that when I go to page 2, I'm shown the result from page 1 and so on. I have tried out different solutions like: Query for all users in a post method based on the filters, ending with ->paginate(NUMBER). Then Session::put('users') in order to be able to retrieve it from a get method so I can return a view with the collection. I've also tried to pass the request object from the post to the get method, but with no result.
I cannot figure out how to preserve old data for the form when visiting page 2, page 3, etc.
Atm, the code looks like:
POST METHOD:
$users = User::select();
//Add gender.
if($request->has('genders'))
{
$users->whereIn('gender_id', $request->genders);
}
//Get matching users.
$users = $users->Paginate(self::paginate);
//Flash collection to session.
Session::put('users', $users);
return Redirect::route('match.show')->withInput();
GET METHOD:
$users = null;
if(Session::has('users'))
{
$users = Session::get('users');
}
else
{
$users = User::Paginate(self::paginate);
}
return View("find-match.show", compact("users"));
Regards, Frederik
Please or to participate in this conversation.