Mohcin Bounouara
Mohcin Bounouara

Reputation: 623

Pagination in Laravel doesn't work

When i put in my view {!! $questions->links(); !!} i don't see the pagination style and the page dont take 6 post per page like i put in my controller ..

My post Controller : class QuestionsController extends Controller {

/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function index()
{


       $questions = \App\Question::latest()->paginate(6);
               $questions = \App\Question::unsolved();
               $bars     = \App\Question::unsolvedbar();
               $links = str_replace('/?', '?', $questions->render());
       return view('questions.index',compact('questions','bars','links'));
}

My Pagination Links in my View: {!! $questions->links(); !!}

Upvotes: 2

Views: 1133

Answers (2)

Shivam Chawla
Shivam Chawla

Reputation: 731

This is because you are overwriting your $questions variable

$questions = \App\Question::latest()->paginate(6);
$questions = \App\Question::unsolved();

Cant really tell you more without the unsolved() function declaration.

Upvotes: 2

Gabriel Moreira
Gabriel Moreira

Reputation: 29

Add this to your view:

{!! $questions->render() !!}

If you want to paginate the links you should do something like this:

$links = $questions->links()->paginate();

And in the view add:

{!! $links->render() !!}

Upvotes: 0

Related Questions