shawnyv's avatar

Check for Pagination?

Hi all,

I'm trying to reuse a view across a few different controller methods / routes, and it's working fine except that I want to paginate all but 1 of them.

I have one method that calls a collection, then does some work on it, and then outputs it to the page. I can't figure out how to paginate this correctly, and if I just pass a full collection the "$collection->render()" method on my view breaks down.

So is there a way to check for pagination? Something like this would be awesome:

@if($collection->isPaginated)

@endif

Thanks for any help!

0 likes
2 replies
bestmomo's avatar

If you query with paginate you get a LengthAwarePaginator object otherwise you get a Collection, so you can check this type.

1 like
jmfs's avatar
@if($collection instanceof Illuminate\Pagination\LengthAwarePaginator)
....
@endif

not sure if there's a way to compare without the namespacing...

1 like

Please or to participate in this conversation.