Hello & welcome,
Foam like substance in the spit along with stomach discomfort
indicates the presence of digestion problem though your are eating healthy. Digestion irregularities are associated with increased acidity in the stomach which in turn may present with foamy saliva.
This is because, if whatever we eat, is not digested properly, naturally body has to produce more & more acid to digest the food we ate. Now, during sleep this acid containing fluid is being regurgitated by the patient making the throat & oral cavity sore. To compensate this soreness or irritation, large amount of saliva is produced by body to wash the mucosal lining.
You should visit your dentist
to evaluate the condition clinically to get the proper diagnosis as treatment will be varying depending upon it.
Keep your oral cavity clean as much as you can. Avoid over eating. Though food is healthy, over eating may make you suffer from indigestion
Use of Anti Acidic drugs are of special importance but should be taken after visiting your dentist or your Physician only.