Chcę zrobić licznik odwiedzin każdego artykułu. Mam w bazie w tabeli pole które przechowuje te wartości i chciałbym je inkrementować po każdym wejściu. Próbowałem tak
/**
* @Route("/artykul/{id}", name="show")
*/
public function show($id,InformationsRepository $informationsRepository)
{
$em = $this->getDoctrine()->getManager();
$articl = $em->getRepository(Informations::class)->find($id);
$author = $em->getRepository(User::class)->findBy(
array(),array('id' => 'DESC'));
$query=$em->createQuery(
'SELECT u.email FROM App\Entity\Informations i join App\Entity\User u with i.author=u.id and i.id='.$id
);
$query2=$em->createQuery(
"UPDATE App\Entity\Informations i SET i.viewsCounter=(SELECT u.viewsCounter FROM App\Entity\Informations j where j.id=$id)+1 where i.id='.$id"
);
$result=$query->getSingleResult();
$statement = $em->getConnection()->prepare($query2);
$statement->execute();
$result3 = $statement->fetchAll();
if (!$articl) {
throw $this->createNotFoundException(
'No product found for id '.$id
);
}
return $this->render('miasta/show.html.twig', [
'dane' => $articl,
'autor'=>$result]
);
}
ale mam błąd
Catchable Fatal Error: Object of class Doctrine\ORM\Query could not be converted to string
Znalazłęm informacje że trzeba dodać funkcję toString i dodałem ale nadal ten sam błąd