Ma'dan bin Abi Talhah (may Allah have mercy on him) says that Sayyiduna Umar (may Allah be pleased with him) delivered the sermon on Friday, and in it was: O people, you eat from these two foul plants, namely onion and garlic, yet I used to see that whenever the Prophet (peace and blessings be upon him) noticed their smell on someone, he would have him taken out to al-Baqi'. So whoever wishes to eat them, let him kill their smell by cooking them.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 5064