You must do this at the database level, not at the PHP/ORM level or it could result in a race condition.
src/Repository/ExampleRepository.php:
<?php
namespace App\Repository;
use App\Entity\Example;
use Doctrine\ORM\EntityRepository;
/**
* Class ExampleRepository
* @package App\Repository
*/
class ExampleRepository extends EntityRepository {
// [...]
/**
* @param Example $entity
*/
public function incrementCount(Example $entity): void
{
$this
->createQueryBuilder('e')
->update()
->set('e.count', 'e.count + 1')
->where('e.id = :id')
->setParameter('id', $entity->getId())
->getQuery()
->execute();
}
}