Umar bin Khattab reported,

I heard the Prophet ﷺ say, "People, actions are judged only by intentions, and each person will have only what they intended. Whoever's migration is to Allah and His Messenger, his migration is to Allah and His Messenger. But whoever migrates for some worldly gain he seeks or a woman he wishes to marry, his migration is to whatever he migrated for."

Bukhari 6953

Sahih

حدثنا أبو النعمان حدثنا حماد بن زيد عن يحيى بن سعيد عن محمد بن إبراهيم عن علقمة بن وقاص قال سمعت

عمر بن الخطاب رضي الله عنه يخطب قال

سمعت النبي ﷺ يقول يا أيها الناس إنما الأعمال بالنية وإنما لامرئ ما نوى فمن كانت هجرته إلى الله ورسوله فهجرته إلى الله ورسوله ومن هاجر إلى دنيا يصيبها أو امرأة يتزوجها فهجرته إلى ما هاجر إليه

البخاري 6953صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Trickery
Chapter
Avoiding tricks, and that every person receives according to their intention in oaths and other matters
Numbering
Darussalam 6953
Bukhari 6953