Anas was asked about garlic, and he said, "The Messenger of Allah ﷺ said, 'Whoever eats from this plant should not come near us or pray with us.'"
سئل أنس عن الثوم؟ فقال: قال رسول الله ﷺ: من أكل من هذه الشجرة فلا يقربنا، ولا يصلي معنا.
Bukhari narrated it in the Book of Foods (5451), and Muslim in the Book of Mosques (562), both through Abdul-Aziz bin Suhayb, with the same chain. The wording given is Muslim's.