From Amirul Mu'minin Abu Hafsir (Umar Al Khattab) said, “I’ve heard Prophet S.A.W has said” ;

Indeed, all deeds are with an intention. Indeed, every person will only gets something by what he has intended to. Whoever migrate for the sake of Allah and Prophet S.A.W (PBUH), then the migration is accepted by Allah and Prophet S.A.W (PBUH) and whoever migrate for the sake of Dunya (worldly) or for a woman that he wants to marry, then the migration will give him something similar with the migration intention as a result.

—  (متفق عليه)
Sahih Bukhari & Muslim