src/Entity/VehicleCategory.php line 24
<?phpnamespace App\Entity;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\GetCollection;use App\Repository\VehicleCategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\String\Slugger\AsciiSlugger;#[ApiResource(operations: [new Get(),],normalizationContext: ['groups' => ['category:read']],security: "is_granted('PUBLIC_ACCESS')")]#[ORM\Entity(repositoryClass: VehicleCategoryRepository::class)]class VehicleCategory{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[Groups(['vehicle:read', 'category:read'])]#[ORM\Column(length: 255)]private ?string $name = null;#[ORM\OneToMany(mappedBy: 'category', targetEntity: Vehicle::class)]private Collection $vehicles;#[ORM\Column(length: 255, nullable: true)]private ?string $url = null;public function __construct(){$this->vehicles = 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;$this->setUrl($name);return $this;}/*** @return Collection<int, Vehicle>*/public function getVehicles(): Collection{return $this->vehicles;}public function addVehicle(Vehicle $vehicle): self{if (!$this->vehicles->contains($vehicle)) {$this->vehicles->add($vehicle);$vehicle->setCategory($this);}return $this;}public function removeVehicle(Vehicle $vehicle): self{if ($this->vehicles->removeElement($vehicle)) {// set the owning side to null (unless already changed)if ($vehicle->getCategory() === $this) {$vehicle->setCategory(null);}}return $this;}public function getUrl(): ?string{return $this->url;}public function setUrl(?string $url): self{$slugger = new AsciiSlugger('cs');$slug = $slugger->slug($url, '-')->lower();$this->url = $slug->toString();return $this;}}