Preheat the oven to 375°F and lightly grease an 8-by-8-inch baking dish.
Heat the olive oil in a large skillet over medium heat. Add the sliced leeks and minced garlic, then cook for 4 to 5 minutes until the leeks soften.
Spread half the potato slices in an even layer in the baking dish. Top with half the cooked leeks and all the white beans.
Add the remaining potato slices and leeks. Sprinkle with thyme, salt, and pepper.
Pour the milk evenly over the layers, then scatter the Parmesan cheese on top.
Cover the dish with foil and bake for 30 minutes. Remove the foil and bake for 15 more minutes until the potatoes are tender and the top turns lightly golden.