Preview:
/**
     * Checks if a Campaign is UNIQUE by name and creatorUser.
     */
    public function checkIfUnique(BanRule $entity): bool
    {
      // NOTE: this is the new entity created, by default is never set isDeleted() on creating. It will fail always
        if (true == $entity->getIsDeleted()) {
            return true;
        }

        $checkEntity = $this->findOneBy([
            'user' => $entity->getUser(),
            'email' => $entity->getEmail(),
            'phone' => $entity->getPhone(),
        ]);

        if (empty($checkEntity)) {
            return true;
        }
      // NOTE: This will fail always => and skipped. Lead to false, hence no saving if we got 1 record already
        if ($checkEntity->getId() == $entity->getId()) {
            return true;
        }
        dd($checkEntity, $entity, $checkEntity->getId() == $entity->getId());
        return false;
    }
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter