src/Entity/BlogCategory.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassBlogCategoryRepository::class)]
  8. class BlogCategory
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length255)]
  15.     private ?string $name null;
  16.     #[ORM\OneToMany(mappedBy'category'targetEntityBlog::class)]
  17.     private Collection $blogs;
  18.     #[ORM\Column(length255)]
  19.     private ?string $slug null;
  20.     public function __construct()
  21.     {
  22.         $this->blogs = new ArrayCollection();
  23.     }
  24.     public function getId(): ?int
  25.     {
  26.         return $this->id;
  27.     }
  28.     public function __toString():string
  29.     {
  30.         return $this->name;
  31.     }
  32.     public function getName(): ?string
  33.     {
  34.         return $this->name;
  35.     }
  36.     public function setName(string $name): static
  37.     {
  38.         $this->name $name;
  39.         return $this;
  40.     }
  41.     /**
  42.      * @return Collection<int, Blog>
  43.      */
  44.     public function getBlogs(): Collection
  45.     {
  46.         return $this->blogs;
  47.     }
  48.     public function addBlog(Blog $blog): static
  49.     {
  50.         if (!$this->blogs->contains($blog)) {
  51.             $this->blogs->add($blog);
  52.             $blog->setCategory($this);
  53.         }
  54.         return $this;
  55.     }
  56.     public function removeBlog(Blog $blog): static
  57.     {
  58.         if ($this->blogs->removeElement($blog)) {
  59.             // set the owning side to null (unless already changed)
  60.             if ($blog->getCategory() === $this) {
  61.                 $blog->setCategory(null);
  62.             }
  63.         }
  64.         return $this;
  65.     }
  66.     public function getSlug(): ?string
  67.     {
  68.         return $this->slug;
  69.     }
  70.     public function setSlug(string $slug): static
  71.     {
  72.         $this->slug $slug;
  73.         return $this;
  74.     }
  75. }