The Prophet ﷺ said, "Whoever has eaten from this tree should not come near the mosques."
حدثنا أحمد بن حنبل حدثنا يحيى عن عبيد الله عن نافع
أن النبي ﷺ قال من أكل من هذه الشجرة فلا يقربن المساجد
Bukhari narrated it, Adhan, Chapter on What Has Been Said Concerning Raw Garlic, Onion, and Leek, hadith no. 853, and Muslim, Mosques, Chapter on the Prohibition of One Who Has Eaten Garlic or Onion from Attending, etc., hadith no. 561, from the hadith of Yahya Qattan through this route, and it is in Musnad Ahmad, 2/20, 21.