Answer the question
In order to leave comments, you need to log in
How to update values in Doctrine 2.6 ORM row?
There is such a method, they are added to the database without problems, the question is how to update the values \u200b\u200bif the qr_code is unique?
public function store(Request $request, Response $response)
{
$params = (object)$request->getParams();
$entityManager = $this->container->get('em');
$dataRepository = $entityManager->getRepository('App\Models\Entity\QrCode');
$result = $dataRepository->findOneBy(['qr_code' => $params->qr_code]);
if(!$result) {
$data = (new QrCode())
->setUserId($params->user_id)
->setQrCode($params->qr_code)
->setAmount($params->amount)
->setBox($params->box);
$logger = $this->container->get('logger');
$logger->info('QRcode added!', $data->getValues());
$entityManager->persist($data);
$entityManager->flush();
} else {
$data = false;
}
$return = $response->withJson($data, 201)->withHeader('Content-type', 'application/json');
return $return;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question