PHP code example of happyr / entity-exists-validation-constraint

1. Go to this page and download the library: Download happyr/entity-exists-validation-constraint library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

happyr / entity-exists-validation-constraint example snippets


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;

    // ...

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;

    // ...