src/Entity/Category.php line 13
<?phpnamespace App\Entity;use App\Repository\CategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;#[ORM\Entity(repositoryClass: CategoryRepository::class)]#[UniqueEntity(fields: ['category_name'], message: 'Il existe déjà une catégorie avec ce nom.')]class Category{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 255, unique: true)]private ?string $category_name = null;#[ORM\OneToMany(mappedBy: 'product_category', targetEntity: Product::class)]private Collection $products;public function __construct(){$this->products = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getCategoryName(): ?string{return $this->category_name;}public function setCategoryName(string $category_name): self{$this->category_name = $category_name;return $this;}/*** @return Collection<int, Product>*/public function getProducts(): Collection{return $this->products;}public function addProduct(Product $product): self{if (!$this->products->contains($product)) {$this->products->add($product);$product->setProductCategory($this);}return $this;}public function removeProduct(Product $product): self{if ($this->products->removeElement($product)) {// set the owning side to null (unless already changed)if ($product->getProductCategory() === $this) {$product->setProductCategory(null);}}return $this;}public function __toString(): string{return $this->category_name;}}