Call to a member function persist() on null
Meu controlador:
public function handle(Request $request): Response
{
$body = $request->getContent();
$data = json_decode($body);
$medico = new Medico();
$medico->setNome($data->nome);
$medico->setCrm($data->crm);
$this->em->persist($medico);
$this->em->flush();
return new JsonResponse($medico->extract());
}
Meu model:
<?php
namespace App\Entity;
class Medico
{
public int $crm;
public string $nome;
function getCrm(): int
{
return $this->crm;
}
function setCrm($crm): self
{
$this->crm = $crm;
return $this;
}
function getNome(): string
{
return $this->nome;
}
function setNome($nome): self
{
$this->nome = $nome;
return $this;
}
public function extract()
{
return get_object_vars($this);
}
}