Bruna has an idea a day, and she's tired of going through SQL in the console. She wants a page to add her dishes: /kitchen/new-dish. The form is ready, and the navigation already leads to it (the “Kitchen” link).
Your mission
In CuisineController::nouveauPlat() (new dish), when the form is submitted (POST):
- Read the
nom(name),description,prix(price) andspecialite(specialty) fields. - Reject invalid data, with a 422 status code and a message:
- no name → “Give the dish a name.”;
- a zero or negative price → “The price must be greater than zero.”;
- a dish already on the menu (same slug) → “This dish is already on the menu.”.
- Create the
Plat, with a slug made from its name (“Onion Soup Gratinée” →onion-soup-gratinee). - Save it, then redirect to its page.
Reminder
The EntityManager is the guardian of the database. persist() hands it a new object; flush() writes everything that changed, in one transaction. Symfony's slugger turns a text into a URL identifier, accents and apostrophes included.