The Messenger of Allah ﷺ said, "When one of you stands in prayer, let him not spit in front of him, for he is conversing with Allah as long as he remains at his place of prayer, nor to his right, for there is an angel on his right. Let him rather spit to his left or beneath his foot, and then bury it."
وقال رسول الله ﷺ إذا قام أحدكم من الصلاة فلا يبصق أمامه فإنه مناج لله ما دام في مصلاه ولا عن يمينه فإن عن يمينه ملكا ولكن ليبصق عن شماله أو تحت رجله فيدفنه
This is a sahih hadith, narrated by Muslim through other than the route of Abu Hurairah (vol. 2, p. 76), and by Bukhari in the Book of Prayer from Ishaq bin Nasr, from Musa bin Ismail, and from Yahya bin Bukayr. Malik also related it in similar wording in Muwatta, in the chapter on phlegm in the masjid and what is disliked in that regard. Muhammad said, "One should not spit in front of oneself, nor to one's right, nor to one's left, but should spit beneath one's left foot."The version in Muwatta states that the Messenger of Allah ﷺ saw spittle on the qiblah wall of the masjid, so he scraped it off, then turned to the people and said, "When one of you is praying, he should not spit in front of himself, for Allah is in front of him while he prays."