It is narrated from Sayyiduna Mughirah bin Shu'bah (may Allah be pleased with him); he said: One day I ate, then came to the mosque while the Prophet (peace and blessings be upon him) was leading the prayer. When the Messenger of Allah (peace and blessings be upon him) completed his prayer, he said: "Whoever eats anything from this plant (garlic and the like) must not come near our mosque." I said: "O Messenger of Allah! Give me your hand." So I put his (peace and blessings be upon him) hand (inside my shirt) onto my chest, and he (peace and blessings be upon him) saw that it was bandaged, so he said: "Except for one who has an excuse."
Hadith Referenceالمعجم الكبير للطبراني / باب الميم / 18127