k2gl/entity-exist
k2gl/entity-exist is a lightweight Laravel package for checking whether an entity exists before your app acts on it. It provides simple, reusable existence checks for guard clauses, validation flows, and safe record lookups, helping keep null-related errors out of your code.
Architecture fit. The package is a Symfony Validator constraint backed by Doctrine ORM — not a Laravel package. It is applied as an attribute/annotation on Doctrine entities and resolved by a ConstraintValidator holding an EntityManager. Laravel's validation pipeline is illuminate/validation, where rules implement ValidationRule::passes($attribute, $value) and are resolved from the container. There is no shared extension point: a Symfony constraint cannot be registered with Laravel's validator without bridging the entire Symfony Validator component. Framework mismatch, not a wiring gap.
Integration feasibility. To use it as-is we would pull in symfony/validator, doctrine/orm, and a second persistence layer running alongside Eloquent — dual ORM, dual connection config, dual migration story — to obtain behavior Laravel already ships natively (exists:table,column, unique, Rule::exists()->where()). Feasibility as-is: low. The semantics are reproducible as a custom Laravel rule in roughly 50 lines.
Technical risk.
Key questions.
Rule::exists()->where() does not?ignore ID? How is it configured and is it fail-closed?EntityManager or DB is unavailable — validation error or infrastructure error?composer audit and any advisory history on the maintainer?Stack fit. Poor for Laravel. Good only for Symfony 5/6/7 + Doctrine ORM 2/3.
Migration path. Do not adopt. Build an internal equivalent that mirrors the intent with explicit, auditable options:
ValidationRule implementation accepting a model class or repository contract (not a raw table string).where constraints, withTrashed/onlyTrashed, and tenant scope derived from authenticated context.app/Rules) so every service shares one implementation and one audit surface.Compatibility. If a legacy Symfony service exists, it can consume this package — keep that isolated to that repo and do not attempt to share it across the framework boundary. Cross-framework reuse would be via a validation contract we own, not via the library.
Sequencing.
composer audit and a read of the validator source before merge.exists: string rules where tenancy or soft-delete semantics matter.Maintenance. Adopting this in a Laravel app adds symfony/validator and doctrine/orm — an ongoing upgrade tax for two frameworks the team otherwise does not run, incurred for one validation rule. Not defensible.
Support. No vendor, no SLA, one maintainer, zero dependents means no community workarounds to lean on. Internal ownership is required from day one, which is another argument for owning the ~50-line equivalent outright.
Scaling. Every constraint evaluation is a database round trip. On bulk imports or list endpoints this becomes N queries unless batched or cached. Our internal rule should support request-scoped caching or a preloaded ID set to keep imports linear.
Failure modes.
Ramp-up. The library itself is small; a competent Laravel developer reads it in under an hour. The real ramp-up cost is the Symfony/Doctrine conceptual surface — EntityManager, constraint metadata, attribute vs. annotation resolution — plus the operational burden of a second persistence layer. That cost is paid permanently and buys functionality we already have.
How can I help you explore Laravel packages today?