This is a paginator-specific method. Total items should be calculated like this:

```php
if ($collection instanceof Paginator) {
    $payload['total_items] = (int) $collection->getTotalItemCount();
} elseif (is_array($collection) || $collection instanceof Countable) {
    $payload['total_items'] = count($collection);
}
```