Sayyiduna Ubayy bin Ka'b (may Allah be pleased with him) said: There was a man who would attend the prayer despite living far from the mosque. It was said to him: Buy a donkey to ride in the heat and the darkness. He said: By Allah! I would not like my house to be next to the mosque. The Prophet (peace and blessings be upon him) was informed of this. He was asked about it, and he said: O Messenger of Allah! Are not my footsteps, and my returning to my home and family and my coming, recorded (for reward)? The Messenger of Allah (peace and blessings be upon him) said: "You will receive the reward of what you intended."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب النذور / 20105