Skip to content

Instantly share code, notes, and snippets.

@aelfannir
Created December 10, 2021 09:49
Show Gist options
  • Save aelfannir/f84490c7fc1dc655cbee6b39911405a2 to your computer and use it in GitHub Desktop.
Save aelfannir/f84490c7fc1dc655cbee6b39911405a2 to your computer and use it in GitHub Desktop.
<?php
//...
class Dci
{
/**
* @Groups("dcis:read", "dcis:write", "medicaments:write")
* @ORM\ManyToMany(targetEntity=Medicament::class, inversedBy="dcis", cascade={"persist"})
*
*/
private $dci;
}
<?php
//...
class Medicament
{
/**
* @Groups("medicaments:read", "medicaments:write", "dcis:write")
* @ORM\ManyToMany(targetEntity=Dci::class, mappedBy="dci", cascade={"persist"})
*/
private $dcis;
}
<?php
//...
class ApiController extends AbstractController
{
//...
public function create(Request $request): JsonResponse
{
$object = $request->request->get('object');
$context = [
AbstractNormalizer::GROUPS => ['medicaments:write']
];
$medicament = $this->serializer->denormalize($object, Medicament::class, 'json', $context);
return new JsonResponse(
$this->serializer->normalize($result),
Response::HTTP_CREATED
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment