Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deevo's avatar

Handling Empty Paginated Collections

So I am having a problem. To start, my skill level is probably not as advanced as many users here so sometimes even little things that may seem obvious give me some grief.

I am grabbing some DB results from a query and paginating them from the controller. I want to show some sort of feedback to the user if no results were returned from their search. The problem is when I dump the variable, I am returning a Illuminate\Pagination\LengthAwarePaginator Object and all of the properties are protected so I clearly can't access them.

So, my question is, what kind of conditional do you use to check if a collection returned 0 results in a view so you can give feedback to the user?

0 likes
2 replies
hasnatbabur's avatar

$paginator = User::paginate(10); OR $paginator = User::simplePaginate(10);

Now you can check if paginator has items in it or not like this:

if($paginator->isNotEmpty()){ //// }

if($paginator->isEmpty()){ //// }

This is more efficient way checking if pagination has items. Thanks

1 like

Please or to participate in this conversation.