Olá, fiz passo a passo o vídeo, porém recebo o seguinte erro ao digitar localhost:8080/medicos.
(2/2) MethodNotAllowedHttpException
No route found for "GET /medicos": Method Not Allowed (Allow: POST)
in RouterListener.php line 145
at RouterListener->onKernelRequest(object(RequestEvent), 'kernel.request', object(EventDispatcher))
in EventDispatcher.php line 298
at EventDispatcher::Symfony\Component\EventDispatcher\{closure}(object(RequestEvent), 'kernel.request', object(EventDispatcher))
in EventDispatcher.php line 260
at EventDispatcher->doDispatch(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.request', object(RequestEvent))
in EventDispatcher.php line 235
at EventDispatcher->callListeners(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.request', object(RequestEvent))
in EventDispatcher.php line 75
at EventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
in HttpKernel.php line 127
at HttpKernel->handleRaw(object(Request), 1)
in HttpKernel.php line 68
at HttpKernel->handle(object(Request), 1, true)
in Kernel.php line 198
at Kernel->handle(object(Request))
in index.php line 25
MedicosController.php
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MedicosController{
/**
*@Route("/medicos", methods={"POST"})
*/
public function novo(Request $request): Response
{
$corpoRequisicao = $request->getContent();
$dadoEmJson = json_decode($corpoRequisicao);
$medico = new Medico();
$medico->crm = $dadoEmJson->crm;
$medico->nome = $dadoEmJson->nome;
return new JsonResponse($medico);
}
}
Medico.php
<?php
namespace App\Entity;
class Medico
{
public $crm;
public $nome;
}
O que pode ser?