Umar Ibn Al Khattab Reported that Prophet Muhammad Pbuh said :
إِنَّمَا الْأَعْمَالُ بِالنِّيَّاتِ وَإِنَّمَا لِكُلِّ امْرِئٍ مَا نَوَى فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ فَهِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ وَمَنْ كَانَتْ هِجْرَتُهُ لِدُنْيَا يُصِيبُهَا أَوِ امْرَأَةٍ يَنْكِحُهَا فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ
Verily, deeds are only with intentions (neeyat). Verily, every person will have only what they intended (neeyat). Whoever emigrated to Allah (swt) and his messenger (PBUH), his emigration is for Allah (swt) and his messenger (PBUH). Whoever emigrated to get something in the world (dunya) or to marry a woman, his emigration is for that to which he emigrated.
Source: Sahih Al Bukhari (54)