Do porcupines lay eggs?
Porcupines and hedghogs, as eutherian mammals, reproduce by mating and gestating to the birth of fully-formed offspring. You’re mixing them up with echidnas and platypi, which are monotremes and lay eggs, and with marsupials, like kangaroos and koalas, which give birth to only partly-formed offspring which then must develop further in the pouch. Eutherians, marsupials, and monotremes are completely separate branches of the mammal phylogeny. Being spiky is an example of convergent evolution rather than a genetic link.