Al-Imām al-Bukhārī - upon whom be mercy - narrates: Ādam related to us; he said: Ibn Abī Dhi’b related to us; he said: al-Zuhrī related to me, from ‘Aṭā’ ibn Yazīd al-Laythī,
from Abū Ayyūb al-Anṣārī - Allāh Almighty be content with him - who said: The Messenger of Allāh ﷺ said: “When any one of you goes to relieve himself, he should neither face the Qiblah nor turn his back towards it. Rather, he should face the east or the west.”
حَدَّثَنَا آدَمُ قَالَ: حَدَّثَنَا ابْنُ أَبِي ذِئْبٍ قَالَ: حَدَّثَنَا الزُّهْرِيُّ، عَنْ عَطَاءِ بْنِ يَزِيدَ اللَّيْثِيِّ، عَنْ أَبِي أَيُّوبَ الْأَنْصَارِيِّ قَالَ: قَالَ رَسُولُ اللهِ ﷺ
إِذَا أَتَى أَحَدُكُمُ الْغَائِطَ، فَلَا يَسْتَقْبِلِ الْقِبْلَةَ وَلَا يُوَلِّهَا ظَهْرَهُ، شَرِّقُوا أَوْ غَرِّبُوا.
Reference: Sahih Al Bukhari 144