Evolution is driven by the environment.Those organisms which adapt to an environment of darkness or water will have different aspects of adaption that allow them to survive in specific conditions. Animals who need to find food from the side will evolve to have eyes on the sides of their heads because their parents had a survival advantage when slight changes toward side vision emerged. The environment which favors these slight changes naturally "selects" by granting a slight edge, hence more progeny survive in the long term.
There are many configurations of eyes for organisms. Some have just the ability to see light, some have eyes that face forward. Some eyes are big. Some are small. Some are on stalks, some are complex, such as the compound eyes of bees and flies. Some animals, like certain bats, insects and amphibians will be effectively blind. They have eyes appropriate to what best favors their ability to get food, mate and live in low-light environments, such as caves.
For most grazing animals, a wider field of vision is needed for herbivores to detect predators from the side and from behind. It is the opposite for most predators. These carnivores rely upon being able to stalk, move forward with stealth, focus keenly upon movement and pounce upon herbivores they eat. Also, forward-facing eyes allow binocular vision. This helps those organisms such as humans and other primates, too, to have depth perception and to be able to rely upon a full visual field of what lies ahead.
In the case of some flatfish, for example the eyes on a halibut or sole are located on the top side of the head.The fish which was most favored in this environment, was the fish that could see above to evade prey, find food, choose mates and generally thrive by the selected advantage of top-side eyes.
The evolution of the eye is complex. It so baffled early naturalists, that many concluded that eyes were a sign of top-down creation. That is, they assumed something as complex and intricate as an eye required a creator. But it is also observable, and was pointed out by other scientists, that most organisms have two eyes. They have other physical bilateral symmetry as well. This points to common descent. It shows that the eyes are traits that many organisms have in common. They display diversity, but this just exemplifies variations on a theme. To many reasoning people, vast numbers of variations show either a common thread of DNA passing down countless generations, or a top-down creator who only could come up with a few basic ideas, then tweak them slightly each generation.
It is said that eyes are the windows to the soul. This may be, but there is even more intricacy to them than that adage allows. Eyes are adaptations that truly allow the light of truth to enter in the ever-changing landscape of interdependent life.