I review my laravel/blade/livewire code for better performance and I try to remove any objects from blade files, like
$item->related_subitems->count
or
foreach( $item->related_subitems() as ... )
also I think it is better to pass to view template array of data, not object or collections.
But trying to implemented it, I encountered that to use pagination of listing I need to pass collenction of models.
Are there some pagination implementation with array?
What do you this about using objects/arrays in blade templates? If there is a sence to move to array of data?
I'm not sure that there are really performance problems with collections. With Laravel, a collection is an array (of objects).
Sure you can manage the pagination without any collection / object, but then you have to put in your array the needed informations (first page, number of pages, current page, ...).
You can also map your collection to an array, then retrieving exactly what you want / need. But this is then a one more action before displaying the view.
I agree with @vincent15000 , there is none performance problems with collections, what you will want to care about is what those collections data have, so don't send data to the frontend that you won't use, so, sometimes instead of sending a collections of models, with all their data inside, maybe you want to think about it and use DTOs that will have only the data you will need on the frontend, so be careful not sending duplicated data to the frontend