sergisergio /
Ads
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Entity; |
||
| 4 | |||
| 5 | use Doctrine\Common\Collections\ArrayCollection; |
||
| 6 | use Doctrine\Common\Collections\Collection; |
||
| 7 | use Doctrine\ORM\Mapping as ORM; |
||
| 8 | use Symfony\Component\Validator\Constraints as Assert; |
||
| 9 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
||
| 10 | use ApiPlatform\Core\Annotation\ApiResource; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository") |
||
| 14 | * @UniqueEntity( |
||
| 15 | * fields={"name"}, |
||
| 16 | * message="Cette catégorie est déjà enregistrée !" |
||
| 17 | * ) |
||
| 18 | * @ApiResource |
||
| 19 | */ |
||
| 20 | class Category |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @ORM\Id() |
||
| 24 | * @ORM\GeneratedValue() |
||
| 25 | * @ORM\Column(type="integer") |
||
| 26 | */ |
||
| 27 | private $id; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @ORM\Column(type="string", length=255) |
||
| 31 | * @Assert\NotBlank |
||
| 32 | */ |
||
| 33 | private $name; |
||
| 34 | |||
| 35 | public function __construct() |
||
| 36 | { |
||
| 37 | $this->adverts = new ArrayCollection(); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 38 | } |
||
| 39 | |||
| 40 | public function getId(): ?int |
||
| 41 | { |
||
| 42 | return $this->id; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function getName(): ?string |
||
| 46 | { |
||
| 47 | return $this->name; |
||
| 48 | } |
||
| 49 | |||
| 50 | public function setName(string $name): self |
||
| 51 | { |
||
| 52 | $this->name = $name; |
||
| 53 | |||
| 54 | return $this; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |