The village photographer, in other words Odette's nephew, took a picture of last year's pumpkin under the moon. Madame Lou wants it on the front page. But not every article will have a photo: you need a property that can hold nothing.
Your mission
- Add a read-only
photoproperty toArticle, of type?string, which isnullby default. It holds the name of a file in thepublic/images/folder. - Give the festival article the photo
'citrouille.svg'(citrouille is French for pumpkin). - In
afficherArticle(), below the title, when the article has a photo, show<img class="photo" src="images/citrouille.svg" alt="…">, with the article's title as the alt text.
Reminder
null means “no value”. A type preceded by ?, like ?string, accepts a string or null. Before using a nullable value, check that it is there: if ($article->photo !== null). The alt text describes the image to anyone who cannot see it.
To replace null with a fallback value, the ?? operator saves you the if: $article->photo ?? 'no-photo.svg' is the photo if there is one, and 'no-photo.svg' otherwise. It also works for an array key that may be missing: $tableau['cle'] ?? ''.