<?php
namespace App\Entity;
use App\Repository\BlogCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: BlogCategoryRepository::class)]
class BlogCategory
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Blog::class)]
private Collection $blogs;
#[ORM\Column(length: 255)]
private ?string $slug = null;
public function __construct()
{
$this->blogs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function __toString():string
{
return $this->name;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Blog>
*/
public function getBlogs(): Collection
{
return $this->blogs;
}
public function addBlog(Blog $blog): static
{
if (!$this->blogs->contains($blog)) {
$this->blogs->add($blog);
$blog->setCategory($this);
}
return $this;
}
public function removeBlog(Blog $blog): static
{
if ($this->blogs->removeElement($blog)) {
// set the owning side to null (unless already changed)
if ($blog->getCategory() === $this) {
$blog->setCategory(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): static
{
$this->slug = $slug;
return $this;
}
}