Published: Oct 28, 2023 by Hamog
Here are a few tips and tricks that I have learnt along the way to help optimize your database queries in Laravel. Sometimes, little changes can add up and make a big difference overall.
Adding a select()
to your query means that you only retrieve the fields that you are going to use, rather than returning every field in your model. If your view doesn’t need the field then save some memory by only fetching and returning the fields you need.
Rather than: