Sunan Abi Dawud Book 28, Hadith 88
The garlic and onions were mentioned before the Messenger of Allah (ﷺ). He was told: The most severe of them is garlic. Would you make it unlawful? The Prophet (ﷺ) said: Eat it, and he who eats it should not come near this mosque until its odour goes away.
He who eats garlic or onion must keep away from us. Or he said: must keep away from our mosque or must sit in his house. A dish containing green vegetables was brought to him, and noticing that it had an odour he asked (about it). He was told that it contained some vegetables. He then said: Bring it near, to one of his companion who was with him. When he saw it, he abominated eating it, and said: eat for I hold intimate converse with one with whom you do not. Ahmad b. Salih said: Ibn Wahb explained the word badr as meaning dish.
Zirr ibn Hubaysh said: Hudhayfah traced, I think, to the Messenger of Allah (ﷺ) the saying: He who spits in the direction of the qiblah will come on the Day of Resurrection in the state that his saliva will be between his eyes; and he who eats from this noxious vegetable should not come near our mosque, saying it three times.