render('vehicle/admin.html.twig', [ 'vehicles' => $vehicleRepository->findAll(), ]); } #[Route('/new', name: 'app_vehicle_new', methods: ['GET', 'POST'])] public function new(Request $request, EntityManagerInterface $entityManager): Response { $vehicle = new Vehicle(); $form = $this->createForm(VehicleType::class, $vehicle); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->persist($vehicle); $entityManager->flush(); return $this->redirectToRoute('app_vehicle_index', [], Response::HTTP_SEE_OTHER); } return $this->render('vehicle/new.html.twig', [ 'vehicle' => $vehicle, 'form' => $form, ]); } #[Route('/{id}', name: 'app_vehicle_show', methods: ['GET'])] public function show(Vehicle $vehicle): Response { return $this->render('vehicle/show.html.twig', [ 'vehicle' => $vehicle, ]); } #[Route('/{id}/edit', name: 'app_vehicle_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Vehicle $vehicle, EntityManagerInterface $entityManager): Response { $form = $this->createForm(VehicleType::class, $vehicle); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->flush(); return $this->redirectToRoute('app_vehicle_index', [], Response::HTTP_SEE_OTHER); } return $this->render('vehicle/edit.html.twig', [ 'vehicle' => $vehicle, 'form' => $form, ]); } #[Route('/{id}', name: 'app_vehicle_delete', methods: ['POST'])] public function delete(Request $request, Vehicle $vehicle, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$vehicle->getId(), $request->getPayload()->getString('_token'))) { $entityManager->remove($vehicle); $entityManager->flush(); } return $this->redirectToRoute('app_vehicle_index', [], Response::HTTP_SEE_OTHER); } }