Halve the onions lengthways and peel them. Cut lengthways into very fine slices (about 2 mm thick). Melt the butter in a large, deep frying pan over medium heat and add the onion, star anise, and a pinch of salt. Cook, stirring every 5 minutes, until the onion has wilted and released its liquid. Reduce the heat to low.
Cook the onion for 30-40 minutes, stirring every 10-15 minutes, until golden brown.
The onion will stick to the bottom of the pan and brown underneath, so stir and scrape as this happens. Season with a little more salt, remove the star anise, and transfer the onion to a bowl to cool. You can make this ahead of time and refrigerate it, covered, for up to three days.
Preheat the oven to 160°C. Combine the stock, cream, wine, and butter in a saucepan. Bring to a boil over medium heat, then reduce the heat to low and simmer until reduced by about half. Place the thyme and rosemary in a mixing bowl, and strain the stock mixture over the herbs. Set aside to Infuse.
Peel the potatoes and cut them into thin slices, about 2 mm thick (use a mandolin if you have one)—season generously with salt and pepper. Grease the base and sides of a 30 cm x 20 cm baking dish or 8 petite cast-iron cocotte pans 10 cm diameter x 8 cm deep with butter.
Make a layer of potato over the base of the dish. Spread a small amount of the onion over the potato and then sprinkle with a little of the parmesan.
Make another layer of potato, followed by more onion and parmesan. Continue layering the ingredients, finishing with a layer of potato on top. Strain the remaining stock mixture and pour it carefully over the potato. Cover with foil and bake for 45-60 minutes or until the liquid has been absorbed and the potato is tender when pierced with a knife. Uncover and cook for 10-15 minutes until golden brown on top.
Set aside to rest for 15-20 minutes before serving.
Garnish with a few thyme leaves.