adamjhn's avatar

Do you know why the pagination links are not appearing?

I have this index() method below that gets the draft congresses, that is congresses where status column has the value "D". Then in the view I have "{{$draftCongresses->links()}}" but the pagination is not appearing. Do you know where can be the issue?

 public function index(Request $request){

        $pageLimit = 5;
        $user = $request->user();

        $draftCongresses = $user->congresses()->where('status','D')->paginate($pageLimit);

        return view('users.index',
            compact('user','draftCongresses'));
    }

Then in the index.blade.php:

@foreach($draftCongresses as $draftCongress)
    @if(!empty($draftCongress))

    <li class="list-group-item">
        <p{{$draftCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
        <h5>{{$draftCongress->name}}</h5>
    </li>
@endif
@endforeach
{{$draftCongress->links()}}

0 likes
5 replies
rin4ik's avatar

$draftCongresses not $draftCongress

@foreach($draftCongresses as $draftCongress)
    @if(!empty($draftCongress))

    <li class="list-group-item">
        <p{{$draftCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
        <h5>{{$draftCongress->name}}</h5>
    </li>
@endif
@endforeach
{{$draftCongresses->links()}}
1 like
adamjhn's avatar

Thanks, but same issue, no error, but the pagination links dont appear.

The {{dd($draftCongresses->links())}} shows:

HtmlString {#262 ▼
  #html: ""
}

And:

$draftCongresses = $user->congresses()->where('status','D')->paginate($pageLimit);
        dd($draftCongresses);

shows:

LengthAwarePaginator {#265 ▼
  #total: 5
  #lastPage: 1
  #items: Collection {#273 ▼
    #items: array:5 [▶]
  }
  #perPage: 5
  #currentPage: 1
  #path: "http://layout.test/user/profile"
  #query: []
  #fragment: null
  #pageName: "page"
}
skoobi's avatar

If theres only 5 items showing on the $draftCongresses array it wont show i don't think. Try setting $pageLimit to 2 and see if it paginates

rin4ik's avatar

@adamjhn that's strange. try these

{{$draftCongresses->render()}}
return view('users.index')->with('draftCongresses',$draftCongresses)->with('user',$user);

and don't forget to hard refresh the browser (ctrl+f5)

Edit: @skoobi correct pagination will display if you have more than 5 results

Please or to participate in this conversation.