Booking was a smash hit: the tavern is never empty. Bruna wants to add to her menu every week, but adding a dish means… changing the code. Unacceptable. From now on, the dishes will live in a database.
For that, Symfony relies on Doctrine: you describe a PHP class (an entity), and Doctrine takes care of the table and the SQL.
Your mission
Turn the App\Entity\Plat (dish) class into a Doctrine entity, stored in the plat table:
| Property | Database type | Note |
|---|---|---|
id |
integer | identifier generated by the database |
slug |
string (100) | unique |
nom (name) |
string (100) | |
description |
long text | |
prix (price) |
decimal number (float) | |
specialite (specialty) |
boolean | false by default |
The properties and their getters and setters are already written: only the mapping is missing, in other words the #[ORM\…] attributes.
The console
Console tab, next to the preview: it's a real bin/console.
doctrine:schema:validate: checks your mapping;doctrine:schema:update --force: creates the table in the preview's database;dbal:run-sql "SELECT * FROM plat": queries the database in SQL.
In a real project, you evolve the schema with migrations (
make:migration). Here, the preview's database lives in your browser and starts from scratch on every load:schema:updateis enough.