Sahih Muslim 564a
Jabir reported: The Messenger of Allah ﷺ said: He who eats garlic or onion should remain away from us or from our mosque and stay in his house. A kettle was brought to him which had (cooked) vegetables in it, He smelt (offensive) odour in it. On asking he was informed of the vegetables (cooked in it). He said: Take it to such and such Companion. When he saw it, he also disliked eating it. (Upon this). he (the Holy Prophet) said: You may eat it, for I converse wkh one with whom you do not converse.
وَحَدَّثَنِي أَبُو الطَّاهِرِ، وَحَرْمَلَةُ، قَالاَ أَخْبَرَنَا ابْنُ وَهْبٍ، أَخْبَرَنِي يُونُسُ، عَنِ ابْنِ شِهَابٍ، قَالَ حَدَّثَنِي عَطَاءُ بْنُ أَبِي رَبَاحٍ، أَنَّ جَابِرَ بْنَ عَبْدِ اللَّهِ، قَالَ - وَفِي رِوَايَةِ حَرْمَلَةَ وَزَعَمَ أَنَّ رَسُولَ اللَّهِ ﷺ قَالَ " مَنْ أَكَلَ ثُومًا أَوْ بَصَلاً فَلْيَعْتَزِلْنَا أَوْ لِيَعْتَزِلْ مَسْجِدَنَا وَلْيَقْعُدْ فِي بَيْتِهِ " . وَأَنَّهُ أُتِيَ بِقِدْرٍ فِيهِ خَضِرَاتٌ مِنْ بُقُولٍ فَوَجَدَ لَهَا رِيحًا فَسَأَلَ فَأُخْبِرَ بِمَا فِيهَا مِنَ الْبُقُولِ فَقَالَ " قَرِّبُوهَا " . إِلَى بَعْضِ أَصْحَابِهِ فَلَمَّا رَآهُ كَرِهَ أَكْلَهَا قَالَ " كُلْ فَإِنِّي أُنَاجِي مَنْ لاَ تُنَاجِي " .