The Messenger of Allah ﷺ noticed some phlegm on the wall of the mosque. He picked up a pebble and scraped it off, then said, "When one of you needs to expel phlegm, he should not spit in front of his face, nor to his right. Let him spit to his left or beneath his left foot."
حدثنا حجاج حدثنا ليث حدثني عقيل عن ابن شهاب عن حميد بن عبد الرحمن أن
أن رسول الله ﷺ رأى نخامة في حائط المسجد فتناول رسول الله ﷺ حصاة فحتها ثم قال إذا تنخع أحدكم فلا يتنخم قبل وجهه ولا عن يمينه ليبصق عن يساره أو تحت قدمه اليسرى
Its isnad is sahih. Aqeel is Ibn Khalid the memorizer. The hadith has previously appeared under Abu Hurairah at number 10052 with similar wording, see also numbers 1543 and 2225. It is also found in Bukhari, through the route of Zuhri from him with its wording, 1/509, numbers 408 and 411 of Fath, and in Muslim, 1/389, number 548, in the Book of Masjids, on the prohibition of spitting in the masjid.