I'm working on a request to pick up some result from the database but I have an error and I don't know how to resove it
in my repository :
public function findBySearchField($salary, $contract, $experience, $training)
{
return $this->createQueryBuilder('a')
->andWhere('a.salary = :sal')
->setParameter('sal', $salary)
->andWhere('a.contract = :con')
->setParameter('con', $contract)
->andWhere('a.experience = :exp')
->setParameter('exp', $experience)
->andWhere('a.training = :tra')
->setParameter('tra', $training)
->orderBy('a.postedAt', 'DESC')
->getQuery()
->getResult()
;
}
in my controller :
public function index(Request $request, AdvertRepository $advertRepository): Response
{
$form = $this->createForm(ResearchType::class);
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
$salary = $form->get('salary')->getData();
$contract = $form->get('contract')->getData();
$experience = $form->get('experience')->getData();
$training = $form->get('training')->getData();
return $this->render('advert/index.html.twig', [
'form' => $form->createView(),
'adverts' => $advertRepository->findBySearchField(
['salary' => $salary],
['contract' => $contract],
['experience' => $experience],
['training' => $training]
),
]);
}
return $this->render('advert/index.html.twig', [
'form' => $form->createView(),
'adverts' => $advertRepository->findAll(),
]);
}
I have an error "Notice: Undefined offset: 2"
However when I make this request in phpMyAdmin it returns what I am looking for