There is a hadith that reads, "Allah did not send any prophet except that he shepherded sheep." Did Prophet Muhammad, sallallaahu ‘alayhi wa sallam, work as a shepherd? Did he shepherd sheep or goats? What is the wisdom behind that?
All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
It was narrated that the Prophet, sallallaahu ‘alayhi wa sallam, said, "Allah did not send a prophet except that he shepherded sheep." The Companions, may Allah be pleased with them, asked, "Did you do the same?" The Prophet, sallallaahu ‘alayhi wa sallam, replied, "Yes, I used to shepherd the sheep of the people of Makkah in return for some qirats (gold or silver currency)." [Al-Bukhari]
A shepherd is a person who shepherds sheep and goats as well. We have not found any tradition that specifies whether the Prophet, sallallaahu ‘alayhi wa sallam, shepherded sheep or goats.
As for the wisdom behind working in this job, Ibn Hajar mentioned some aspects thereof in Fat-h Al-Bari while commenting on the aforesaid hadith. He said:
Scholars stated that the wisdom behind inspiring the Prophets to work as shepherds before assuming Prophethood is to train them how to be in charge of their people. Also, shepherding teaches them patience and compassion since treating their herds patiently, being keen to gather them when they disperse throughout the pasture, taking them from one pasture to another better one, warding off their enemies of wild beasts and thieves, as well as knowing their different natures and realize how they quickly go away in different directions as well as their need for a maintainer…, all this trains the Prophets to be patient with their people and know their different natures and variant ways of thinking, etc. In this way, they will be keen to maintain their people, treat the weak kindly and look after their affairs. This will make it easier for them to endure all these tasks instead of being entrusted therewith without former training.
Consequently, the wisdom behind inspiring the Prophets to work as shepherds before Prophethood is related to disciplining and upbringing them, on one hand, and it also has an economic aspect as well.
Allah knows best.
You can search for fatwa through many choices