No. Rodents can chew through foam. Also, unless the foam is UV light stabilized, it will breakdown in sunlight, dry rot, and degrade so that the problem can reoccur. Foam does, however, help reduce the attractiveness of a structure because it slows or stops airflow, which is believed to be one of the enticements for rodents to gnaw and/or enter. For best results, cover the opening with 1/4" metallic screen, hardware cloth, flashing, or some other gnaw-proof barrier and then fill the opening with foam or caulk to both stop airflow and secure the barrier in place.