Skip to content

Instantly share code, notes, and snippets.

@atillay
Created November 11, 2021 16:55
Show Gist options
  • Save atillay/516817b237d67dc26171bb9633765865 to your computer and use it in GitHub Desktop.
Save atillay/516817b237d67dc26171bb9633765865 to your computer and use it in GitHub Desktop.
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* collectionOperations={
* "post"={
* "validation_groups"={"Default", "my-entity:post"}},
* }
* },
* itemOperations={
* "put"={
* "validation_groups"={"Default", "my-entity:put"}},
* },
* "put_custom"={
* "method"="PUT",
* "path"="/my-entity/{id}/custom",
* "validation_groups"={"Default", "my-entity:put_custom"}},
* }
* }
* )
*/
class MyEntity {
public $id;
/**
* @Assert\NotBlank(groups={"my-entity:post", "my-entity:put"})
* @Assert\Type("string")
*/
public $name;
/**
* @Assert\NotBlank(groups={"my-entity:put_custom"})
* @Assert\Length(min=1, max=3)
*/
public $specialValue;
public $createdAt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment