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

syntaxerron's avatar

Laravel Accessors on Query Builder

I am currently working on a Laravel API project and I am retrieving a lot of records. I used eloquent, however it is slow when retrieving at least 500 records. I have seen on other posts that it would be better to use query builder but I have Laravel accessors to retrieve some data which can only be called upon retrieving records with eloquent. Is it possible to use it on a query builder and how can I implement it?

0 likes
4 replies
syntaxerron's avatar

Records have been paginated, I think I'm having N+1 issues just like what @snapey said. Thank you for the response.

Snapey's avatar
Snapey
Best Answer
Level 122

check you dont have n+1 issues if you are fetching related data in accessors

1 like
syntaxerron's avatar

I'll try to look on this one. Thank you for the response

Please or to participate in this conversation.