iamdvsan's avatar

Laravel Pagination not working

I am trying to paginate records, but it shows me error.

public function index(){
    $posts = Post::get();

    return view('index')->with('posts', $post);
}

If I use following link, it will show error.

{{ $posts->links() }}
1 like
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@iamdvsan

You have missed one thing. It should be like this-

public function index(){
    $posts = Post::paginate(10);

    return view('index')->with('posts', $post);
}

Now you are able to use links().

{{ $posts->links() }}
6 likes
iamdvsan's avatar

Ohh Shit.

Thanks. You are the boss.

1 like

Please or to participate in this conversation.