Olá meu caro! Por gentileza, saberia me dizer porque o método persist(), está como Indefined?
Abaixo meu código do MedicosController.php:
<?php
namespace App\Controller;
use App\Entity\Medico;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MedicosController extends AbstractController
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @Route("/medicos", methods={"POST"})
*/
public function novo(Request $request): Response
{
$headers = $request->getContent();
$data = json_decode($headers);
$medico = new Medico();
$medico->crm = $data->crm;
$medico->nome = $data->nome;
$this->entityManager->persist();
return new JsonResponse($medico);
}
}