Twice in less than 14 months President Donald Trump shut down the government to obtain funding for his border wall — a key piece of the enforcement-first agenda that his hardline White House adviser Stephen Miller has pushed on him. He's lost badly both times.

If Trump were smart, he'd ditch Miller. And then he'd look for innovative strategies to advance border security that involve not slamming — but welcoming — immigrants and that he could sell to his base without alienating everyone else.

The good news for Trump is no one can accuse him of not trying hard enough to push his ultra-restrictionist plans — except for maybe Ann Coulter. He dialed up his anti-immigration rhetoric during his campaign — accusing immigrants of everything from raising crime to decimating native wages — to rally the American people. And once in office, he recruited Miller to help him plot his immigration strategy and work Capitol Hill given that Miller had vast experience on this issue when working for former Attorney General Jeff Sessions when Sessions was a senator.

Thanks partly to Miller, Trump instantly canceled both DACA (Deferred Action for Childhood Arrivals) and DAPA (Deferred Action for Parental Arrivals), President Obama's programs to give a temporary reprieve from deportation for DREAMers and undocumented aliens without a criminal record. And then Trump used the prospect of deporting DREAMers as leverage to drive a tough immigration bargain with a Republican-controlled Congress.

This was a remarkable move for the simple reason that, until then, not even the most rabid anti-immigration hardliners such as Rush Limbaugh had in their wildest dreams imagined using DREAMers as pawns. All they had hoped for were policies that would first secure the border — by building a wall and aggressively prosecuting border jumpers — before handing a one-time "amnesty" to the 11 million undocumented aliens in the country. Miller, however, prodded Trump last January to shut down the government and strong-arm Congress into giving him not only $25 billion for a border wall but also a 40 percent cut in legal immigration in exchange for legalizing a mere 700,000 DREAMers.

This backfired spectacularly. Not only did Democratic Senators balk but key Republicans did too. More crucially, this move, along with Sessions' notorious zero-tolerance border enforcement approach that involved taking away kids from asylum seekers to deter them from coming, repelled Americans, helping cost Republicans the House in the midterms.

Still, Miller refused to let Trump give up. He was instrumental in prodding the president to walk away from a deal to sign a clean continuing resolution to fund the government during the lame duck session this past December and demand $5.7 billion in wall funding. Miller's hope was that the wall would prove so popular that the new Democratic House Speaker Nancy Pelosi would cave rather than withhold the money.

But the opposite happened. Pelosi's popularity inched up as the government shutdown dragged on while Trump's base, for the first time, started abandoning him, forcing him to agree to reopen the government for three weeks.

During this time a bipartisan group of lawmakers is supposed to hammer out a deal to fund his wall in exchange for legalizing DREAMers and other aliens whose visa status Trump has revoked. But the odds that they'll reach any kind of agreement aren't great given that Pelosi remains implacably opposed to handing him money for the wall, as Trump himself has acknowledged.

So the chances are Trump will once again find himself at crossroads: take the Miller path or a new path.

The Miller path would mean making good on this threat to declare a national emergency to raid some other government department to fund his wall. But the problem with that strategy is that it won't accomplish anything, given that courts will step in and stop him, just as they have done with his efforts to kill DACA and defund sanctuary cities. At the same time, it will irritate not just Democrats but also Republicans who fear what a Democratic president might do with the precedent Trump would set. Sen. Roy Blunt (R-Mo.) has already warned Trump against it.

The lesson here is that Miller's immigration ideas simply don't have widespread appeal and are both a political and moral loser.

Trump's other option would be to pull a Nixon-goes-to-China move and pivot hard on the issue. Just as Richard Nixon's famously hawkish foreign policy gave him street cred to sell a peace deal with China to his conservative base, Trump could do something similar on immigration policy.

The broad-brush strokes of what this might look like are not hard to figure out. Most of Trump's base is interested in enhancing border security — not necessarily tormenting immigrants. However, the enforcement-first approach they've been sold won't actually deliver security for the simple reason that walls and crackdowns don't address the root cause of the problem, namely the lack of legal avenues for working and living in the U.S., especially for South American migrants.

So the trick is to convince Trump voters that border security and legalization can occur in tandem and in fact prioritizing the first over the second is exactly backwards. There are various ways to do this.

Cato Institute's Alex Nowrasteh has proposed creating an additional visa category called the gold card that would give foreigners the option of working and living legally in the United States — but not citizenship — after paying a tariff. Congress could adjust tariff rates by age and education to guarantee that all immigrants make a net positive fiscal contribution. This would potentially cut back illegal flows and give the country much greater operational control over the border than physical barriers ever could. It would also generate additional funds to go after drug traffickers or criminals who pose a genuine security threat.

Another related proposal developed by investor and immigration reform group founder Steve Kuhn (full disclosure: He is temporarily renting my house) is called IDEAL (Immigration Designed to Enhance Immigration Lives). This would involve handing out around two million new visas annually — a mix of five-year visas at $25,000 each and one-year visas at $2,500 each. The former would appeal to employers who want high-tech workers and the latter to those who use low-skilled seasonal help. The fees might seem high but are actually quite reasonable compared to the astronomical legal fees that high-tech employers have to pony up to obtain H-1B visas for foreign techies and, alternatively, the bureaucratic hoops that, say, developers and landscape companies have to jump through to obtain seasonal workers. Kuhn estimates that IDEAL would generate up to $70 billion in annual revenues for the U.S. treasury that could be used to enhance border security, prop up the welfare safety net, or otherwise mitigate any negative impact of immigration.

No doubt these proposals would have to be finessed and developed more but the point is that they offer the kind of win-win that should not be hard to sell to Trump's base.

To keep doing the same thing over and over again in the face of failure is the definition of insanity. It's time Trump tried something different.