src/Entity/Products.php line 15
<?phpnamespace App\Entity;use App\Entity\Trait\CreatedAtTrait;use App\Entity\Trait\SlugTrait;use App\Repository\ProductsRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: ProductsRepository::class)]class Products{use CreatedAtTrait;use SlugTrait;#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 255)]#[Assert\NotBlank(message: 'Le nom du produit ne peut pas être vide')]#[Assert\Length(min:8,max:200,minMessage: 'Le titre doit faire au moins {{ limit }} caractères',maxMessage: 'Le titre ne doit pas faire plus de {{ limit }} caractères')]private ?string $name = null;#[ORM\Column(type: Types::TEXT)]private ?string $description = null;#[ORM\Column]private ?int $price = null;#[ORM\Column]#[Assert\PositiveOrZero(message: 'Le stock ne peut pas être négatif')]private ?int $stock = null;#[ORM\ManyToOne(inversedBy: 'products')]#[ORM\JoinColumn(nullable: false)]private ?Categories $categories = null;#[ORM\OneToMany(mappedBy: 'products', targetEntity: Images::class, orphanRemoval: true, cascade:['persist'])]private Collection $images;#[ORM\OneToMany(mappedBy: 'products', targetEntity: OrdersDetails::class)]private Collection $ordersDetails;public function __construct(){$this->images = new ArrayCollection();$this->ordersDetails = new ArrayCollection();$this->created_at = new \DateTimeImmutable();}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;}public function getDescription(): ?string{return $this->description;}public function setDescription(string $description): self{$this->description = $description;return $this;}public function getPrice(): ?int{return $this->price;}public function setPrice(int $price): self{$this->price = $price;return $this;}public function getStock(): ?int{return $this->stock;}public function setStock(int $stock): self{$this->stock = $stock;return $this;}public function getCategories(): ?Categories{return $this->categories;}public function setCategories(?Categories $categories): self{$this->categories = $categories;return $this;}/*** @return Collection<int, Images>*/public function getImages(): Collection{return $this->images;}public function addImage(Images $image): self{if (!$this->images->contains($image)) {$this->images->add($image);$image->setProducts($this);}return $this;}public function removeImage(Images $image): self{if ($this->images->removeElement($image)) {// set the owning side to null (unless already changed)if ($image->getProducts() === $this) {$image->setProducts(null);}}return $this;}/*** @return Collection<int, OrdersDetails>*/public function getOrdersDetails(): Collection{return $this->ordersDetails;}public function addOrdersDetail(OrdersDetails $ordersDetail): self{if (!$this->ordersDetails->contains($ordersDetail)) {$this->ordersDetails->add($ordersDetail);$ordersDetail->setProducts($this);}return $this;}public function removeOrdersDetail(OrdersDetails $ordersDetail): self{if ($this->ordersDetails->removeElement($ordersDetail)) {// set the owning side to null (unless already changed)if ($ordersDetail->getProducts() === $this) {$ordersDetail->setProducts(null);}}return $this;}}