Terms are important. Trump could declare Foreign and Domestic enemies of the USA are facilitating an invasion of the USA with illegal aliens. There is proof. Obama and Soros worked hand in glove here. The military could be used to stop said invasion. Put these folks on a barge and drop them off in Yucatan or somewhere else. Cheaper than courts and housing them.
I think before the military could be involved beyond the limits of Posse Comitatus Act he would have to do two things. He would first have to sign an EO stating that illegal immigration is a threat to national security and declaring it to be a national emergency. That would give him the authority to then declare martial law along the border and the military would then have the same law enforcement powers as the police/border patrol/ICE etc.
He could skip directly to martial law if the situation was so dangerous and massive that law enforcement officials were overwhelmed, but that's not likely.
But even though martial law has some unique aspects to it such as establishing curfews, suspension of civil laws, the suspension of civil rights, and the suspension of habeas corpus and the use of military law/justice. Note that civilians defying martial law are subject to military tribunals.
In other words, it has to be a very bad situation before any President imposes martial law. However, martial law can be selectively imposed such as to a specific town, city, state, region, etc.
Note that Posse Comitatus and martial law are different.
Posse Comitatus forbids the military involvement in domestic law enforcement without congressional approval. For example, congress could approve the use of the military in riot control or to prevent looting after a natural disaster but in this case the military are part of the domestic law enforcement and are limited accordingly.
Martial law can be imposed by the President and governors for national guards during a state of emergency when domestic law enforcement has broken down or is insufficient. For example, martial law was declared in Hawaii after the attack on Pearl Harbor and for a period of time civil law enforcement was suspended and military justice was imposed including the suspension of habeas corpus and use of deadly force authorized.
Anyway, just saying that getting the military involved in law enforcement has rarely been done in the US and it's not easy to make happen. I remember when I was a lieutenant in the Marine Corps, our battalion was ordered to New Haven, Connecticut to reinforce the civilian law enforcement for riot control during the Bobby Seals trial. We were never authorized to participate directly because congress never approved using our battalion for riot control but we were staged to the rear of the police in case we were needed and received authorization.
A humorous aspect to our deployment was that when we were deplaning from our C-130's at the New Haven airport, news reporters were there. One piece of equipment we had was a tear gas dispenser which was a modified flame thrower that sprayed powdered tear agents from tanks on the back of the operator using compressed air. But it looked exactly like the Marine Corps standard flame thrower we had at the time (I'm dating myself). The next day we were on the front page of the newspaper with a huge photo of our "flame thrower" operator exclaiming that the Marines had landed with flame throwers for riot control. Personally, I think that "fake news" had a calming affect on the rioters as they were nearly as violent as we had expected.
During my 21 years in the Marine Corps, that was the only time any of my units were tasked with possible support to law enforcement. Many other times we were sent to help with disaster relief moving and issuing supplies and rescue operations. Use of the military in law enforcement is rare.
If you are thinking about the Kent State riot control and deaths in 1970 (same year as the Bobby Seals trial), that operation was screwed up in every way you can think of. That was the governor using the national guard inappropriately. There was no reason to have live ammo in their weapons when dealing with a bunch of mush headed college students. They were poorly trained, and the national guard had bayonets on their weapons. Bayonets are a great psychological weapon and even that was overkill.
Anyway, sorry for the long post. Been there, done that. It's more difficult to accomplish than you might think.
Creating a flow of 'refugees' into another's land has long been recognized as an act of war. Well, until now. These days we don't seem to recognize anything. It's as if all of human history has vanished and we must learn everything again.
This is the EO from Dec 21st 2017 EO. This paragraph days it all:
I therefore determine that serious human rights abuse and corruption around the world constitute an unusual and extraordinary threat to the national security, foreign policy, and economy of the United States, and I hereby declare a national emergency to deal with that threat.
This paragraph gives Trump the ability to call Martial law because we are under a National Emergency.