It is narrated from Sayyiduna Qurrah bin Iyas (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "Whoever eats from these two plants (garlic and onion) should not come near us in our mosque. If you must eat them, then cook them (to remove their smell) before eating."
Hadith Referenceالمعجم الكبير للطبراني / باب القاف / 16115