well, two points:
1) you absolutely CAN choose a commercial mix purpose built for a specific use, i.e. layer feed. And, with the exception of the reduced total calcium (for which there is good nutritional reason), the nutritional offering in the typical "all flock" is as good or better than a similarly branded and market positioned "layer" formulation - worst case is that some of the "excess" in the All Flock is excreted w/o use, but more often, the All Flock - while better - is still somewhat less than the "perfect" diet for that particular bird at that particular moment in its life.
2) birds which forage ARE limited to whatever's available. If its not present in the environment, they can't obtain it. If it is present in the environment, they have to obtain it in the form available - for good or ill. Often, that's ill - particularly if an excess of high fat sources for the needed nutrition are the only (or preferred) source. High fat seeds like sunflower are a good example of this - a chicken getting most of its Met and Lys from sunflower seeds is also ingesting a lot of fat, which brings concerns of its own.
Finally and as reminder, I do both. I provide my birds a commercial feed (one, in fact, that I know is bad for some of them - excess calcium for my roos), and I allow my birds to free range acres at their liesure. They are almost never locked up. Its educated risk taking - i can't know the nutritional value of my acres at any given moment, so I provide a base which meets their minimums (and a bit more), and allow them to forage in addition/as alternative. I put more than minimal effort in ensuring that the pasture is varied in content during every season (to the extent we have seasons here) - but I don't pretend that square footage alone ensures a diet on which they can thrive - particularly as I knwo that the optimal levels of Met - the first and most critical Amino Acid for a chicken - is higher than can be obtained from vegetable sources found in nature, and the availability of animal or insect protein sources in my pasture is largely beyond my control.
I'm not against Commercial Feed. I'm not against Foraging per se. I am for understanding the limitations of whatever you do choose to do. One of the costs of free ranging/foraging is that you simply can't know. Best guess, and some intelligent assumptions based on observation of their forage area is close as it gets, while the likelihood of a bird ever reaching its potential is reduced (how greatly being a factor of breed and forage both - the more we humans have tinkered with the line, the greater its dietary requirements are likely to be to reach its full potential).