Advertisement
RuslanK

Product

May 1st, 2022
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Entity;
  4.  
  5. use App\Repository\ProductRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9.  
  10. /**
  11.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  12.  */
  13. class Product
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.  
  22.     /**
  23.      * @ORM\Column(type="string", length=100)
  24.      */
  25.     private $name;
  26.  
  27.     /**
  28.      * @ORM\ManyToMany(targetEntity=Category::class, mappedBy="product")
  29.      */
  30.     private $Category;
  31.  
  32.     public function __construct()
  33.     {
  34.         $this->Category = new ArrayCollection();
  35.     }
  36.  
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.  
  42.     public function getName(): ?string
  43.     {
  44.         return $this->name;
  45.     }
  46.  
  47.     public function setName(string $name): self
  48.     {
  49.         $this->name = $name;
  50.  
  51.         return $this;
  52.     }
  53.  
  54.     /**
  55.      * @return Collection<int, Category>
  56.      */
  57.     public function getCategory(): Collection
  58.     {
  59.         return $this->Category;
  60.     }
  61.  
  62.     public function addCategory(Category $category): self
  63.     {
  64.         if (!$this->Category->contains($category)) {
  65.             $this->Category[] = $category;
  66.             $category->addProduct($this);
  67.         }
  68.  
  69.         return $this;
  70.     }
  71.  
  72.     public function removeCategory(Category $category): self
  73.     {
  74.         if ($this->Category->removeElement($category)) {
  75.             $category->removeProduct($this);
  76.         }
  77.  
  78.         return $this;
  79.     }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement