Skip to main content
CourseFlix

Eloquent Performance Patterns

2h 12m 50s
English
Paid

Learn how to improve the speed of your Laravel apps by moving more work to the database while still using Eloquent. This course shows you clear steps you can use right away.

The Problem

Slow apps cause stress. Users wait. Servers work too hard. You feel pressure from every side.

You fix N+1 queries. You add indexes. You pay for stronger servers. But some tasks still feel slow and hard to build.

Common Roadblocks

  • You cannot paginate in the database because your checks run in Laravel.
  • You need heavy calculations on large data sets, and you think only PHP can handle them.
  • You sort by values created in your app, not in the database.

You try caching. It helps for a moment. Then you fight new cache bugs and stale data. The loop never ends.

A Different Path

I felt the same pain. So I set out to push as much work as possible to the database. I tested ideas. I broke things. I learned many patterns that changed how I build apps.

With tools like subqueries, conditional aggregates, and smart scopes, pages that once took over 30 seconds now load in under a second.

Why This Matters

I have shared these ideas at events like Laracon Online and Laracon US. I have also written articles on advanced Eloquent patterns.

About the Author: Jonathan Reinink

Jonathan Reinink thumbnail
Hello! My name is Jonathan Reinink. I am a software developer with a particular focus on the web. I run an online business called Church Social, an app that helps churches keep organized online. I am also active in the open source community, particularly within the PHP and Laravel space. My latest contribution has been Inertia.js, a library that lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers. I am also a coauthor of the Tailwind CSS framework.

Watch Online 28 lessons

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 28 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing
0:00
/
#1: Measuring your database performance
All Course Lessons (28)
#Lesson TitleDurationAccess
1
Measuring your database performance Demo
04:43
2
Minimizing memory usage by selecting only
04:29
3
Getting one record from has-many relationships
09:44
4
Creating dynamic relationships using sub queries
06:10
5
Calculating totals using conditional aggregates
04:21
6
Optimizing circular relationships
04:25
7
Setting up multi-column searching
04:07
8
Getting LIKE to use an index
05:05
9
Faster options than whereHas
03:55
10
When it makes sense to run additional queries
03:08
11
Using UNIONs to run queries independently
07:58
12
Fuzzier searching using regular expressions
04:45
13
Running authorization policies in the database
06:04
14
Faster ordering using compound indexes
04:05
15
Ordering by has-one relationships
01:38
16
Ordering by belongs-to relationships
01:39
17
Ordering by has-many relationships
04:21
18
Ordering by belongs-to-many relationships
05:39
19
Ordering with NULLs always last
07:36
20
Ordering by custom algorithms
06:38
21
Filtering and sorting anniversary dates
07:04
22
Making N+1 issues impossible
03:24
23
Ordering data for humans using natural sort
04:20
24
Full text searching with rankings
05:07
25
Getting the distance between geographic points
03:23
26
Filtering by geographic distance
03:00
27
Ordering by geographic distance
01:26
28
Filtering by geospatial area
04:36
Unlock unlimited learning

Get instant access to all 27 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription