What is the meaning of [all’s for the best in the best of all possible worlds]

Everything that happens does so for a good reason, and things in general cannot be any better; generally used to present an optimistic worldview.