<?php
namespace App\Entity;
use App\Repository\PostRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=PostRepository::class)
*/
class Post
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $content;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity=PostImage::class, mappedBy="post", cascade={"persist", "remove"})
*/
private $postImages;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $slug;
public function __construct()
{
$this->postImages = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, PostImage>
*/
public function getPostImages(): Collection
{
return $this->postImages;
}
public function addPostImage(PostImage $postImage): self
{
if (!$this->postImages->contains($postImage)) {
$this->postImages[] = $postImage;
$postImage->setPost($this);
}
return $this;
}
public function removePostImage(PostImage $postImage): self
{
if ($this->postImages->removeElement($postImage)) {
// set the owning side to null (unless already changed)
if ($postImage->getPost() === $this) {
$postImage->setPost(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
}