<?phpnamespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Gedmo\Mapping\Annotation as Gedmo;use Symfony\Component\Validator\Constraints as Assert;/** * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository") */class Category{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @Gedmo\Slug(fields={"name", "id"}) * @ORM\Column(length=128, unique=true) */ private $slug; /** * @ORM\OneToMany(targetEntity="App\Entity\Post", mappedBy="category") */ private $posts; /** * @return mixed */ public function getSlug() { return $this->slug; } /** * @param mixed $slug */ public function setSlug($slug): void { $this->slug = $slug; } public function __construct() { $this->posts = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } /** * toString * * @return string */ public function __toString() { return $this->getName(); } /** * @return Collection|Post[] */ public function getPosts(): Collection { return $this->posts; } public function addPost(Post $post): self { if (!$this->posts->contains($post)) { $this->posts[] = $post; $post->setCategory($this); } return $this; } public function removePost(Post $post): self { if ($this->posts->contains($post)) { $this->posts->removeElement($post); // set the owning side to null (unless already changed) if ($post->getCategory() === $this) { $post->setCategory(null); } } return $this; }}