When we give thanks in all things, we see hardships and adversities in the context of the purpose of life. We are sent here to be tested. There must be opposition in all things. We are meant to learn and grow through that opposition, through meeting our challenges, and through teaching others to do the same.
When we understand the principle that God offers us opportunities for blessings and blesses us through our own adversities and the adversities of others, we can understand why He has commanded us again and again to “thank the Lord thy God in all things” (Doctrine and Covenants 59:7).