Sunan Abi Dawud Book 2, Hadith 87
The Messenger of Allah(ﷺ) said: if anyone enters the mosque, and spits in it, or ejects phlegm, he should remove some earth and bury it there. If he does not do so, then he should spit in his clothes and not come out with it.
The Messenger of Allah(ﷺ) said: Spitting phlegm in the mosque... The narrator then transmitted the rest of the tradition to the same effect.
The Messenger of Allah (ﷺ) said: When a man stands with the intention of saying prayer, or if any of you says prayer, he should not spit before him, nor at his right side; but he should do so at his left side, if there is a place for it; or he should spit under his left foot and then rub it off.