1 like
Sep 9, 2014
5
Level 30
Search Results Paginate
This is my little search function.
$query = Request::get('q');
if ($query)
{
$posts = Post::where('title', 'LIKE', "%$query%")->paginate(15);
}
else
{
$posts = Post::orderBy('id', 'DESC')->paginate(15);
}
return View::make('posts.index', compact('posts'));
Now if there are more than 15 results and i click through the pagination, i get all posts if i go to page 2 and not my search results.
For example if i search "/posts?q=title" and if i go to page 2 the parameters are not passed -> "posts?page=2" How can i solve this problem ?
Level 5
Watch the last part of this video https://laracasts.com/lessons/crazy-simple-pagination.
You can do something like
$posts->appends(Request::only('q'))->links()
6 likes
Please or to participate in this conversation.