christopher's avatar

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 ?

0 likes
5 replies

Please or to participate in this conversation.