Peel, halve and thinly slice onions.
In a large pot or dutch oven, melt butter over medium heat.
When the butter begins to foam, add onions and stir well to coat them in the butter.
Reduce the heat to low and caramelise the onions. This can take 30 minutes - stir only occasionally, or as often as needed to prevent burning. Add a small splash of water if needed. The onions should be a dark brown and taste very sweet.
Once the onions are done, add wine to deglaze the pot. Increase heat to medium and stir thoroughly until most of the wine has evaporated.
Sprinkle flour over onions and and stir well to combine for 1 minute.
Add stock, bay leaves, thyme and stir. Cover and leave to simmer for 30 minutes.
Once the soup is done, slice sourdough and top with cheese. Melt under oven grill/broiler to melt cheese.
Ladle soup into bowls and place the cheesey bread on top, eat immediately.