The Messenger of Allah ﷺ forbade these two plants (i.e. garlic and onions), and he said: He who eats them should not come near our mosque. If it is necessary to eat them, make them dead by cooking, that is, onions and garlic. (Using translation from Abū Dāʾūd 3827)
نَهَى رَسُولُ اللهِ ﷺ عَنْ هَاتَيْنِ الشَّجَرَتَيْنِ الْخَبِيثَتَيْنِ وَقَالَ مَنْ أَكَلَهُمَا فَلَا يَقْرَبَنَّ مَسْجِدَنَا وَقَالَ إِنْ كُنْتُمْ لَا بُدَّ آكِلِيهِمَا فَأَمِيتُمُوهُمَا طَبْخًا قَالَ يَعْنِي الْبَصَلَوَالثُّومَ