I have a symfony function that returns a rest api. I can post data to a new record successfully from an endpoint. This is the symfony controller as shown
$users->setUsername($request->request->get('username'));
$users->setPhonenumber($request->request->get('phonenumber'));
$users->setEmail($request->request->get('email'));
$users->setPassword($request->request->get('password'));
$users->setDateregistered(new \DateTime('now'));
$em->persist($users);
$em->flush();
Assuming that the above inserts a new record successfully into a new table, my challenge is to get the primary key of that table.
try this after flush method:
$userId = $users->getId();
You can do this because doctrine hydrate the variable that you pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With