Hadithcore
Riyad as-Salihin, 4

Jabir bin Abdullah Al-Ansari (May Allah be pleasedwith them) reported:

We accompanied the Prophet (ﷺ) in an expedition when he said, "There are some men in Al-Madinah who are with you wherever you march and whichever valley you cross. They have not joined you in person because of their illness." In another version he said: "They share the reward with you." <b>[Muslim]</b>. It is narrated by Bukhari from Anas bin Malik (May Allah be pleased with him): We were coming back from the battle of Tabuk with the Prophet (ﷺ) when he remarked, "There are people whom we left behind in Al- Madinah who accompanied us in spirit in every pass and valley we crossed. They remained behind for a valid excuse."

وعن أبي عبد الله جابر بن عبد الله الأنصارى رضي الله عنهما قال‏:‏ كنا مع النبي صلى الله عليه وسلم في غزاةٍ فقال‏:‏ ‏"‏إن بالمدينة لرجالاً ماسرتم مسيراً، ولا قطعتم وادياً إلا كانوا معكم حبسهم المرض‏"‏ وفى رواية‏:‏ ‏"‏إلا شاركوكم في الأجر‏"‏ ‏(‏‏(‏رواه مسلم‏)‏‏)‏‏.‏ ‏(‏‏(‏ورواه البخاري‏)‏‏)‏ عن أنس رضي الله عنه قال‏:‏ رجعنا من غزوة تبوك مع النبي صلى الله عليه وسلم فقال‏:‏ ‏"‏ إن أقواماً خلفنا بالمدينة ما سلكنا شعباً ولا وادياً إلا وهم معنا، حبسهم العذر‏"‏‏.‏

References1 variant
In-Book Reference
Introduction, Hadith 4
Sharh · explanationclick to expand
<b>Guidance from the Hadith:</b><br> 1) Anyone who participates in Jihad for the sake of Allah shall receive a reward for the distance he traveled. This is a favor from Allah that the means are rewarded just as much as the deed itself because the means share the same rulings as their objectives.<br> 2) If someone intends to do a good deed but was prevented by a valid excuse, he shall gain the reward of his intention.