src/Entity/Tag.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TagRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassTagRepository::class)]
  8. class Tag
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length255)]
  15.     private ?string $tag_name null;
  16.     #[ORM\ManyToMany(targetEntityProduct::class, mappedBy'product_tags')]
  17.     private Collection $tag_products;
  18.     public function __construct()
  19.     {
  20.         $this->tag_products = new ArrayCollection();
  21.     }
  22.     public function getId(): ?int
  23.     {
  24.         return $this->id;
  25.     }
  26.     public function getTagName(): ?string
  27.     {
  28.         return $this->tag_name;
  29.     }
  30.     public function setTagName(string $tag_name): self
  31.     {
  32.         $this->tag_name $tag_name;
  33.         return $this;
  34.     }
  35.     /**
  36.      * @return Collection<int, Product>
  37.      */
  38.     public function getTagProducts(): Collection
  39.     {
  40.         return $this->tag_products;
  41.     }
  42.     public function addTagProduct(Product $tagProduct): self
  43.     {
  44.         if (!$this->tag_products->contains($tagProduct)) {
  45.             $this->tag_products->add($tagProduct);
  46.             $tagProduct->addProductTag($this);
  47.         }
  48.         return $this;
  49.     }
  50.     public function removeTagProduct(Product $tagProduct): self
  51.     {
  52.         if ($this->tag_products->removeElement($tagProduct)) {
  53.             $tagProduct->removeProductTag($this);
  54.         }
  55.         return $this;
  56.     }
  57. }