Melt the butter in a large pot over low heat. Add the onions, garlic, bay leaves, thyme, and salt and pepper and cook until the onions are very soft and caramelized, about 45 minutes. Make sure to periodically carefully stir the onions so they do not burn, but to ensure they cook evenly.
Add the wine, bring to a boil, reduce the heat and simmer until the wine has evaporated, about 10 minutes. Discard the bay leaves and thyme sprigs.
Dust the onions with the flour and give them a stir. Turn the heat down to low so the flour doesn't burn, and cook for 3 minutes to cook out the raw flour taste.
Now add the beef broth, bring the soup back to a simmer, and cook for 30 minutes. Season the broth to taste, with salt and pepper.
When you're ready to eat, preheat the oven to 450 degrees. Spread some butter on each slice and arrange the baguette slices on a baking sheet in a single layer and bake for about 3 -5 minutes, making sure not to burn them.
Remove from the oven. Set the oven to broil. Ladle the soup in oven-proof high heat bowls. Place 2 baguette slices in each bowl and sprinkle with the Gruyere and broil until bubbly and golden brown, 3 to 5 minutes.