🔥 Laravel Tip: get one column of one record in a one-to-many relationship
Mar 24, 2022
If you're only using one record from your one-to-many relationships, you can use subqueries instead of loading all the records.
For example, if I only need to know the title of the most viewed post from a user.
This can reduce your memory usage significantly.
For example, if I only need to know the title of the most viewed post from a user.
This can reduce your memory usage significantly.
![tip-image-0](https://res.cloudinary.com/dpmeu3otn/image/upload/v1666552370/tips/ldcmc63tw2bla7znsym9.jpg)
Other tips:
🔥 Laravel Tip: Update or create
May 1, 2022
🔥 Laravel Tip: Streaming Results Lazily
Apr 2, 2022