Advanced Querying with Laravel Eloquent
summary
Builds a one‑page LaraCRM demo around 1,000 customers with 500,000 interactions to show real pain from N+1 and heavy memory use. Shows concrete fixes: replace per‑row queries with subselects and scopes, add an Eloquent macro for cleaner subqueries, convert subselects to casts or a hasOne via last_interaction_id, and use orderByRaw for birthday sorting. Demonstrates filters and a visibleTo scope for policy logic in SQL, reaching 3 queries / ~3MB / ~40ms per page.
AI-written summary · about
chapters (24)
- 0:00Intro
- 8:30The Bigger Lesson
- 10:44The Code
- 11:25The Data
- 13:04Base Setup
- 14:06Requirements
- 15:03Adding a Scope
- 15:51Adding a Company
- 17:21Adding a Last Interaction
- 20:25Adding a Query Builder
- 23:03Sub Query
- 24:36Last Interaction Date
- 26:37Improve Last Interaction Date
- 28:23Add Last Interaction Type
- 29:31Add Last Interaction
- 31:35Performance
- 32:41What Next
- 34:38The Scope
- 35:09The Implementation
- 38:12Birthdays
- 41:13Interaction Dates
- 42:15Filtering
- 45:10Filter Scope
- 49:49Re Implement Policies
