Back to the Learning!

Laracasts is packed full with over 1,000 lessons just like this one.

Sign up to get full access or log in to your account and sit back.

Published On Aug. 3rd 2016

Whip Monstrous Code Into Shape: Consider Query Objects

Episode 17 Run Time 4:12

Download

Most tutorials demonstrate the simplest possible Eloquent queries. You know, the one where you do Post::all() and move on. But, in reality, you're often writing significantly more complex queries. So what do we do, when they get too large and gross to keep in the controller? Well, we could extract to the model, we could create a repository, or we could make a single-use query class. Let me show you how; it's easy!

View the demo source for this episode on GitHub.