Expressive Eloquent collections
summary
Builds concrete expressive collections by creating a model-specific collection class and wiring it via newCollection on model, so queries return an InvoiceCollection extends EloquentCollection that carries domain methods like isPaid, totalCost, sortByRelevance and a query-target helper that does one DB update then patches in-memory models. Uses Laravel higher-order collection proxies, Carbon for dates and custom query builders. Result is thinner models, extracted repeated logic, easier unit testing and fewer queries — pattern proves practical in real projects.
AI-written summary · about
chapters (12)
- 0:00Intro
- 1:28Expressive Eloquent Collections What is eloquent?
- 3:54Why I wanted to improve readability
- 4:19The language of a model Problem space specific
- 7:31The language of a collection Set of generic items.
- 12:23Just the beginning
- 12:56Extracting repeated logic Keepin' it DRY
- 13:40Default and improved sorting methods
- 15:40Thinning models
- 19:04Testability
- 22:08Sharing a filtering API with eloquent scopes
- 24:05Encapsulation
related talks
21mUsing the Repository Pattern with Eloquent for Code That Lasts
21mSoftware Design Patterns in Laravel 4
49mLaravel - If, how and why you should use it!
54mState of Laravel
32mDesign Patterns and Packages for Excellent Laravel Backoffices
44mDenormalization With Eloquent: How, Why and When
42mAdvanced Laravel: Avoid unified data models
21mLaravel Doctrine: A Data Mapper Approach
