I wouldn't get all unless necessary, what if it grows to millions of records.
If only a small amount, you can paginate a collection: https://laracasts.com/discuss/channels/guides/paginate-collection-simple-example-guide
See last example, not first.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have two completely different tables and want to get all the records of these two tables and merge the records, is it possible to do that? I could do that with Collections but i would like to paginate this records, and only with a Query instance is possible to paginate (yes, i know, i can paginate a collection with a custom code, but i'm just checking the options here before do that).
That doesn't matter if you tell it to get the same number of fields.
So if the first one has ten fields and the other just eight you can either just get 8 from both or you can add null fields to the second select.
SELECT * FROM
(SELECT id, title artist creator, 'records' type, created_at, some_other_field FROM records
UNION ALL
SELECT id, title author creator, 'books' type, created_at, null some_other_field FROM books)
ORDER BY created_at DESC
LIMIT 10
Please or to participate in this conversation.