Jesus’ birth and early moments on earth are wrapped in fulfilled prophecy. While angels directed a lot of the action, and God used dreams also, I give Joseph credit for paying attention too.
22 But when he heard that Archelaus was reigning over Judea in place of his father Herod, he was afraid to go there. After being warned in a dream, he went to the regions of Galilee.
Matthew 2:22
He didn’t just blindly return to Israel, but exercised caution in the return. And in a dream, he found a solution to the danger that still threatened Jesus.