It is narrated from Sayyiduna Anas bin Malik (may Allah be pleased with him) that he said: We went on the expedition of Tabuk with the Prophet (peace and blessings be upon him). An energetic young man passed by us, and he had his goats with him. We said: If only his youth and his vigour were (spent) in the path of Allah, it would be better for him than this. Our talk had (barely) ended when it reached the Messenger of Allah (peace and blessings be upon him), and he (peace and blessings be upon him) said: "What did you say?" We said: We said such and such. He (peace and blessings be upon him) said: "If he is striving for (the service of) his parents or one of them, he is in the path of Allah; if he is striving to provide for his family, he is in the path of Allah; and if he is striving for (the needs of) himself, he is in the path of Allah."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب النفقات / 15741