Preheat oven to 350°F. Grease and flour a 9x13 inch baking pan.
Whisk flour, sugar, baking soda, and salt together in a large bowl.
Add eggs, the full can of undrained crushed pineapple, and vanilla. Stir until just combined. Fold in nuts if using.
Pour into the prepared pan and bake for 35 to 40 minutes until golden and a toothpick comes out clean.
Cool completely in the pan, at least 1 hour, before frosting.
Beat cream cheese and butter until smooth. Add powdered sugar and vanilla and beat until fluffy. Spread over the cooled cake.
Scatter toasted coconut over the frosted cake before slicing and serving.