I recently learnt about a cool feature in Laravel that allows you to pass a query builder instance (
Illuminate\Database\Query\Builder
) directly to thewhereIn
method of another query builder to reduce the number of separate database queries executed.So I thought I’d put together a quick example to show you how it works.
Before we get started though, it’s important to note that I’m by no means an expert in databases and SQL. Although my hunch is that using the approach I’ll show you will result in better performance, I haven’t done any benchmarks to check this. I just want to highlight that this approach is possible. So please take this as a suggestion of a way to do things rather than a definitive answer as to the best way to do it. Remember to always test and benchmark your code to see what works best for your specific use case.
continue reading on ashallendesign-uk.medium.com
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.