Skip to main content

Eloquent doesn't have an identity map, which means the same database row can end up loaded into multiple instances in the same request. Most of the time you don't notice. Sometimes it bites.

This series is a two-part walkthrough of building one yourself. The first article covers the concept, why it's useful, and a minimal implementation using a custom base model class. The second follows up on the memory implications of that implementation, particularly in long-lived processes like those running on Laravel Octane, and covers how to manage and prevent leaks.

It's a practical series with a working solution at the end of it, but it also ends up walking through enough of Eloquent's internals to give you a better sense of what's happening under the surface. If you've ever wondered why two User::find(1) calls return different objects, this is the explanation and the fix.