There's actually a pretty simple solution to stemming the influx of illegal immigrants from poorer regions to richer rgions. Two, in fact, although one's really just semantics.

First, just let everyone in legally. No such thing as "illegal immigrant" anymore, right ?

Two, help the poorer regions get rich enough that people no longer want to move out of there en masse in search of better prospects. This is really sort of how like it's kinda pointless to wage "war on drugs" so long it's not economically viable for Colombian peasants to cultivate legal crops instead of poppy in face of competition from massively subsidized US agribusiness and no toll barrier for defense.

Simple in theory. Complicated in practice, all the more so as so far as I can tell the US has been pursuing roughly the polarly opposed policies vis-a-vis the main sources of "illegals" for quite a while...