@edmond_brakus
In Symfony 4, you can make search queries for maximum and minimum values using Doctrine Query Builder. Here's an example of how you can achieve it:
1 2 |
use DoctrineORMEntityManagerInterface; use DoctrineORMQueryBuilder; |
1 2 3 4 5 6 |
private $entityManager; public function __construct(EntityManagerInterface $entityManager) { $this->entityManager = $entityManager; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public function searchMinMax() { $queryBuilder = $this->entityManager->createQueryBuilder(); $query = $queryBuilder ->select('MAX(entity.field) as maximum, MIN(entity.field) as minimum') ->from(EntityName::class, 'entity') ->getQuery(); $result = $query->getOneOrNullResult(); // Access the maximum and minimum values $maximum = $result['maximum']; $minimum = $result['minimum']; // ... } |
Replace field
with the name of the field you want to find the maximum and minimum values for, and EntityName
with the actual name of your entity.
Now you can use the $maximum
and $minimum
variables in your controller logic as needed.
Remember to adjust the code to fit your specific use case.