Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Eloquent Identity

Eloquent Identity Laravel Package

sprocketbox/eloquent-identity

View on GitHub
Deep Wiki
Context7

An identity map implementation for Eloquent

Frequently asked questions about Eloquent Identity
What does sprocketbox/eloquent-identity do in Laravel?
It adds an identity map to Eloquent so repeated lookups for the same database row can return the same PHP model instance within a unit of work. This can reduce duplicate hydration and improve in-memory consistency for read-heavy request-scoped flows. It is a code-level ORM lifecycle feature, not a query cache or schema change.
How do I install sprocketbox/eloquent-identity?
Install it with Composer and register the package service provider if your Laravel version does not auto-discover it. Then integrate the provided model trait or configuration so Eloquent models participate in the identity map. Because the last release is from 2021, run composer require in a branch and confirm dependency resolution before adopting it.
Which Laravel and PHP versions are supported?
The package’s Composer constraints are the source of truth, and the last release date of January 2021 suggests it may target an older Laravel/PHP matrix. Do not assume support for Laravel 9, 10, 11, or PHP 8.x without a compatibility spike. Test dependency resolution against your exact application versions before committing engineering time.
Is an identity map safe for Laravel queue workers and Octane?
Identity maps are risky in long-running processes because cached model instances can become stale and memory can grow for the life of the worker. You must explicitly reset the map between jobs, requests, and Octane worker cycles if the package supports it. For queue workers and Octane, treat adoption as high risk unless lifecycle reset and invalidation are proven.
Does it work with Eloquent relationships and eager loading?
The evaluation flags relationship loading, eager loading, refresh, delete, and soft deletes as key areas to verify. An identity map should return consistent instances across find, first, get, and relationship loads within the same unit of work. Add regression tests for these paths on a pilot model before expanding usage.
How are stale model instances invalidated after updates or raw SQL?
Identity maps need explicit invalidation when data changes outside the mapped model lifecycle, such as mass updates, raw SQL, or external write paths. The package maturity signal is low, so you should not assume automatic invalidation across every Eloquent event or observer. Test refresh, mass update, soft delete, and raw SQL scenarios and add application-level reset hooks where needed.
Will it cause memory growth in long-running Laravel processes?
Yes, that is a primary production concern because an identity map can retain model instances for the life of the process unless it has eviction or a reset boundary. Short-lived HTTP requests are a better fit than queue workers or long-running CLI processes. Instrument memory usage during a pilot and define request, job, and test teardown resets.
Can I use it with multiple database connections or multi-tenancy?
The evaluation calls out multiple connections and multi-tenancy as areas requiring verification. An identity map must key instances correctly by connection and tenant context, or it can return the wrong model instance. Run a compatibility spike with representative connection and tenant switching before relying on it.
How should I test an identity map integration in Laravel?
Start with one non-critical, read-heavy model or aggregate and keep plain Eloquent as a feature-flagged fallback. Add regression tests for identity semantics, duplicate-instance reduction, stale reads, event and observer behavior, soft deletes, memory growth, and serialization. Define reset hooks for test teardown so state does not leak between tests.
Is sprocketbox/eloquent-identity actively maintained, or should I fork it?
The repository has a low star count and the last release was in January 2021, so active maintenance is uncertain. If Composer resolution fails against your Laravel/PHP matrix, the decision is either to fork and maintain internally or reject adoption. Do not assume backward compatibility from the MIT license alone.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager