PHPackages                             happyr/entity-exists-validation-constraint - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. happyr/entity-exists-validation-constraint

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

happyr/entity-exists-validation-constraint
==========================================

Verify that your entity exists

1.3.0(1y ago)31180.4k—6.3%10[2 PRs](https://github.com/Happyr/entity-exists-validation-constraint/pulls)MITPHPPHP ^8.1

Since Jul 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Happyr/entity-exists-validation-constraint)[ Packagist](https://packagist.org/packages/happyr/entity-exists-validation-constraint)[ GitHub Sponsors](https://github.com/Nyholm)[ RSS](/packages/happyr-entity-exists-validation-constraint/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (4)Versions (7)Used By (0)

Symfony validator for Entity Exist
==================================

[](#symfony-validator-for-entity-exist)

[![Latest Version](https://camo.githubusercontent.com/5af4062b3065135d34eb9a69fad559e052112ada469e842639bc85a9e137a09b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6861707079722f656e746974792d6578697374732d76616c69646174696f6e2d636f6e73747261696e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/happyr/entity-exists-validation-constraint/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/b3c4bdf34b65226b6eabc42a648792493a947cb77df6812361075f5a939d0b87/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6861707079722f656e746974792d6578697374732d76616c69646174696f6e2d636f6e73747261696e742e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/happyr/entity-exists-validation-constraint)[![Code Coverage](https://camo.githubusercontent.com/0e685ee22afa0adb015ead1e9b3812bebc0d7e7cffd488d925ef60e04eaae9d6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6861707079722f656e746974792d6578697374732d76616c69646174696f6e2d636f6e73747261696e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/happyr/entity-exists-validation-constraint)[![Quality Score](https://camo.githubusercontent.com/eeb2e6843c3d6c5f8f5a726d4029f3414137fffd68203eb678dd9553d7e3e5d9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6861707079722f656e746974792d6578697374732d76616c69646174696f6e2d636f6e73747261696e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/happyr/entity-exists-validation-constraint)[![Total Downloads](https://camo.githubusercontent.com/7450d16892631f6c076f5c472b7f904950ead3eb217e1fe8ffb5b6a11b17dfee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6861707079722f656e746974792d6578697374732d76616c69646174696f6e2d636f6e73747261696e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/happyr/entity-exists-validation-constraint)

A small validator that verifies that an Entity actually exists. This is especially useful if you use Symfony Messenger component. Now you can safely validate the message and put it on a queue for processing later.

```
namespace App\Message\Command;

use Happyr\Validator\Constraint\EntityExist;
use Symfony\Component\Validator\Constraints as Assert;

final class EmailUser
{
    /**
     * @Assert\NotBlank
     * @EntityExist(entity="App\Entity\User")
     *
     * @var int User's id property
     */
    private $user;

    /**
     * @Assert\NotBlank
     * @EntityExist(entity="App\Entity\Other", property="name")
     *
     * @var string The name of "Other". We use its "name" property.
     */
    private $other;

    // ...
```

In case you are using other constraints to validate the property before entity should be checked in the database (like `@Assert\Uuid`) you should use [Group sequence](https://symfony.com/doc/current/validation/sequence_provider.html) in order to avoid 500 errors from Doctrine mapping.

```
namespace App\Message\Command;

use Happyr\Validator\Constraint\EntityExist;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @Assert\GroupSequence({"EmailUser", "DatabaseCall"})
 */
final class EmailUser
{
    /**
     * @Assert\NotBlank
     * @Assert\Uuid
     * @EntityExist(entity="App\Entity\User", groups={"DatabaseCall"}, property="uuid")
     *
     * @var string Uuid
     */
    private $user;

    // ...
```

Install
-------

[](#install)

```
composer require happyr/entity-exists-validation-constraint
```

Then register the services with:

```
# config/packages/happyr_entity_exists_validator.yaml
services:
  Happyr\Validator\Constraint\EntityExistValidator:
    arguments: ['@doctrine.orm.entity_manager']
    tags: [ 'validator.constraint_validator' ]
```

Note
----

[](#note)

The Validator will not produce a violation when value is empty. This means that you should most likely use it in combination with `NotBlank`.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance47

Moderate activity, may be stable

Popularity46

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~414 days

Recently: every ~463 days

Total

6

Last Release

414d ago

Major Versions

0.2.0 → 1.0.02021-07-15

PHP version history (3 changes)0.1.0PHP ^7.2

1.0.0PHP ^7.2 || ^8.0

1.2.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/401ccc5eea13c60cf807ae982af00e368e2166e2f26d8eb541dcd881a57385bc?d=identicon)[Nyholm](/maintainers/Nyholm)

---

Top Contributors

[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (4 commits)")[![aradoje](https://avatars.githubusercontent.com/u/30075502?v=4)](https://github.com/aradoje "aradoje (2 commits)")[![thomasbeaujean](https://avatars.githubusercontent.com/u/5817919?v=4)](https://github.com/thomasbeaujean "thomasbeaujean (2 commits)")[![AxaliaN](https://avatars.githubusercontent.com/u/724353?v=4)](https://github.com/AxaliaN "AxaliaN (1 commits)")[![louisezetterlund](https://avatars.githubusercontent.com/u/51154961?v=4)](https://github.com/louisezetterlund "louisezetterlund (1 commits)")

### Embed Badge

![Health badge](/badges/happyr-entity-exists-validation-constraint/health.svg)

```
[![Health](https://phpackages.com/badges/happyr-entity-exists-validation-constraint/health.svg)](https://phpackages.com/packages/happyr-entity-exists-validation-constraint)
```

###  Alternatives

[digitalrevolution/symfony-validation-shorthand

Validation shorthand for symfony

12108.5k2](/packages/digitalrevolution-symfony-validation-shorthand)[digitalrevolution/symfony-request-validation

Automatic request validation for symfony

1296.0k](/packages/digitalrevolution-symfony-request-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
