Preheat the oven to 350°F (175°C) and grease two 9-inch cake pans.
In a mixing bowl, whisk together the all-purpose flour, baking powder, baking soda, salt, cinnamon, and nutmeg.
In a separate mixing bowl, beat the vegetable oil and granulated sugar together until well combined.
Beat in the eggs, one at a time, until fully incorporated.
Mix in the vanilla extract and grated carrots until fully combined.
Add the dry ingredients to the wet ingredients, mixing until just combined.
Mix in the chopped pecans (if using) until just combined.
Divide the cake batter evenly between the two prepared cake pans.
Bake the cakes for 30-35 minutes, or until a toothpick inserted into the center of the cakes comes out clean.
Allow the cakes to cool completely in the pans.
In a mixing bowl, beat the unsalted butter and cream cheese together until creamy.
Add the powdered sugar and vanilla extract, and beat until fully combined and smooth.
Place one cake layer on a serving plate and spread a layer of the cream cheese frosting on top.
Place the second cake layer on top of the frosting.
Spread the remaining frosting over the top and sides of the cake.
Chill the cake in the refrigerator for at least 30 minutes before serving.