Have a look at https://christophersax.com/2016/custom-lengthawarepaginator-in-laravel/
The slice is not good, just see this part:
If you do expect a somewhat larger result set, you should also include a LIMIT and OFFSET option in your SQL query for optimization (and just pass these results without manually slicing the array).
Slice is fine with smaller results, not 10 million. https://laracasts.com/discuss/channels/guides/length-aware-paginator
Generally pagination with grouping is not efficient, as all needs transversed each time.
Group by is better suited for shorter results like summary reports. I normally do the smallest possible, meaning if quarterly would be enough, then an annual is not needed. Just combine the 4 quarters.