It is narrated from Sayyiduna Qurrah Muzani that the Prophet (peace be upon him) forbade those two foul-smelling plants, onions and garlic, and said: Whoever eats them should not come near our mosque. If you cannot do without eating them, then cook them to remove their odor.
Hadith Referenceمسند احمد / مسند المدنيين رضي الله عنهم اجمعين / 16247
Hadith Gradingحکم دارالسلام:صحيح لغيره، وهذا إسناد حسن