1. Preheat the oven to 375°F (190°C). Grease a 9x13-inch baking dish and set aside.
2. In a large pot of boiling salted water, blanch the green beans for 3-4 minutes until just tender. Drain and immediately transfer to a bowl of ice water to stop the cooking process. Drain again and set aside.
3. In a skillet, melt 1/4 cup of butter over medium heat. Add the sliced onions and cook, stirring occasionally, until caramelized, about 20-25 minutes. Add the minced garlic in the last 5 minutes of cooking. Set aside.
4. In a separate saucepan, melt the remaining 1/4 cup of butter over medium heat. Whisk in the flour to create a roux and cook for 1-2 minutes until golden brown.
5. Slowly pour in the milk and heavy cream, whisking continuously to avoid lumps. Cook the sauce until it thickens, about 5-7 minutes. Season with salt and pepper to taste.
6. Add the Gruyere cheese to the sauce and stir until melted and smooth.
7. In a large mixing bowl, combine the blanched green beans, caramelized onions and garlic, and the cheese sauce. Mix well to coat the green beans evenly.
8. Transfer the green bean mixture to the prepared baking dish and spread it out evenly.
9. In a small bowl, combine the panko breadcrumbs and Parmesan cheese. Sprinkle this mixture over the top of the green beans.
10. Bake the casserole in the preheated oven for 30-35 minutes, or until the top is golden brown and bubbly.
11. Remove the casserole from the oven and let it rest for 5 minutes before serving. Garnish with chopped parsley before serving.