The Fermat equation with polynomial values as base variables