Sunan Abi Dawud Book 28, Hadith 91
I ate garlic and came to the place where the Prophet (ﷺ) was praying; one rak'ah of prayer had been performed when I joined. When I entered the mosque, the Prophet (ﷺ) noticed the odour of garlic.
When the Messenger of Allah (ﷺ) finished his prayer, he said: He who eats from this plant should not come near us until its odour has gone away.
When I finished the prayer, I came to the Messenger of Allah (ﷺ) and said: Messenger of Allah, do give me your hand. Then I put his hand in the sleeve of my shirt, carrying it to my chest to show that my chest was fastened with a belt. He said: You have a (valid) excuse.
The Prophet (ﷺ) said: He who eats from this plant should not come near the mosques.
The Messenger of Allah (ﷺ) forbade these two plants (i.e. garlic and onions), and he said: He who eats them should not come near our mosque. If it is necessary to eat them, make them dead by cooking, that is, onions and garlic.