Preheat your oven to 400°F (200°C). Cut the tops off the garlic heads to expose the cloves, drizzle with olive oil, and wrap in foil. Roast for 35-40 minutes until golden and soft.
While the garlic roasts, rinse the rice under cold water until the water runs clear.
In a large pot or Dutch oven, heat olive oil over medium heat. Add diced onion and cook until translucent, about 5 minutes.
Once the garlic is roasted, squeeze the cloves out of their skins and mash with a fork.
Add the rice to the pot with onions and stir for 2 minutes to toast slightly.
Add the mashed roasted garlic, broth, salt, and pepper. Bring to a boil, then reduce heat to low, cover, and simmer for 18 minutes.
When the rice is almost done, stir in the chopped spinach and butter. Cover and let stand for 5 minutes.
Fluff with a fork and stir in Parmesan cheese if using.