futtern/src/Controller/FoodVendorController.php

71 lines
2.4 KiB
PHP

<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\FoodVendor;
use App\Form\FoodVendorType;
use App\Repository\FoodVendorRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/food/vendor')]
final class FoodVendorController extends AbstractController
{
#[Route('/', name: 'app_food_vendor_index', methods: ['GET'])]
public function index(FoodVendorRepository $foodVendorRepository): Response
{
return $this->render('food_vendor/index.html.twig', [
'food_vendors' => $foodVendorRepository->findAll(),
]);
}
#[Route('/new', name: 'app_food_vendor_new', methods: ['GET', 'POST'])]
public function new(
Request $request,
EntityManagerInterface $entityManager
): Response {
$foodVendor = new FoodVendor;
$form = $this->createForm(FoodVendorType::class, $foodVendor);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($foodVendor);
$entityManager->flush();
return $this->redirectToRoute('app_food_vendor_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('food_vendor/new.html.twig', [
'food_vendor' => $foodVendor,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_food_vendor_show', methods: ['GET'])]
public function show(FoodVendor $foodVendor): Response
{
return $this->render('food_vendor/show.html.twig', [
'food_vendor' => $foodVendor,
]);
}
#[Route('/{id}/edit', name: 'app_food_vendor_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, FoodVendor $foodVendor, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(FoodVendorType::class, $foodVendor);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_food_vendor_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('food_vendor/edit.html.twig', [
'form' => $form,
]);
}
}