Donald Trump will appear with Lou Barletta, the Republican candidate for Senate in Pennsylvania, on 2 August in what’s likely to be a typical Trump fundraiser: the president appearing on stage, talking about how convincingly he won the election and basking in the audience’s applause.

But given Trump’s war on undocumented immigrants, it will represent more than that. It will mark the realisation of the controversial, immigrant-blaming law Barletta introduced more than ten years ago, in the tiny Pennsylvania town of Hazleton – and which Trump revised to win the 2016 election.

The August rally will be the third time in two weeks that a high-profile Trump-supporting figure has stepped in to try and boost Barletta’s currently flagging campaign. On 20 July Nigel Farage, of Brexit fame, popped up at a private fundraiser for Barletta in the ordinarily bucolic town of Harveys Lake, in north-east Pennsylvania. This Monday, Mike Pence stumped for Barletta in Philadelphia.

Given that Barletta is currently lagging 16 points behind his opponent – Bob Casey, a Democrat – and showing little sign of closing that gap, it would seem like a waste of airfare. But some believe Trump’s enthusiasm for Barletta possibly reflects the two men’s approach to, and exploitation of, immigrants.

“Both of them have used immigration as an effective tool to get folks, working-class white folks especially, to blame outsiders, and immigrants especially, for problems that are the result of global capitalism and changes in the global economy,” said Jamie Longazel, an associate professor of political science at City University of New York and author of Undocumented Fears: Immigration and the Politics of Divide and Conquer in Hazleton, Pennsylvania.

Let's drop the euphemisms: Donald Trump is a racist president | Richard Wolffe

Read more

“Just the way they think about about the law as it relates to this stuff – they’re really unwilling to grant rights to immigrants and to people of color generally and really willing to back the interests of white folk.”

Barletta was the second congressman to endorse Trump’s presidential campaign, declaring his support for the then businessman in March 2016.

“I like that he is willing to stand up and fight for the American people as I did as mayor,” Barletta said at the time.

Barletta was referring to his 10-year stint as mayor of Hazleton, population 24,659, during which he vowed to make the city “one of the toughest places in the United States” for undocumented immigrants.

To that end, Barletta introduced the Illegal Immigration Relief Act in 2006, which fined landlords $1,000 a day if they rented property to undocumented people, and meant the city could deny business permits to those employing undocumented workers.

The law was struck down by a district court judge in 2007, and the decision was upheld by a federal appeals court in 2010 and again in 2013. But that Barletta managed to pass it in the first place served as a blueprint of how to tap into anti-immigrant sentiment.

Barletta’s sleight of hand was to convince people that the newly arrived immigrants were to blame for job losses and falling wages, said Tom Baldino, a politics professor at Wilkes University in Luzerne County – which includes Hazleton.

“If you have this part of the electorate, particularly white male Americans, that feels abandoned, that no one is listening, they feel as though they’re losing control to a rising segment of the population that doesn’t look like them or sound like them – them being white Americans – if you’re Trump or Barletta you point to them [immigrants] and say: ‘They’re the problem,’” Baldino said.

In many ways, Hazleton is typical of the towns Trump managed to win in Pennsylvania and across the midwest. A former coal-mining community, when that industry declined, Hazleton’s mostly white residents lost their jobs. When Hazleton began to experience an increase in Latino immigration around 2000 – many moving from New Jersey and New York to take up the cheaper housing in Pennsylvania – this new influx became easy to scapegoat for the hardships the white working class were experiencing.

“It’s almost identical,” Longazel said of the ways Barletta, and later Trump, rode the anti-immigrant wave. “It’s like Hazleton is America now.”

Longazel grew up in Hazleton and is able to provide a unique perspective on what the law – even though it was ultimately ruled unconstitutional – achieved. He said what Barletta tapped into as mayor has returned as Trump has talked of rapists, drug-dealers, and animals flooding into the country.

“My sense was that you know if it was at its peak in 2006, it sort of gradually cooled a bit over time,” Longazel said. “But I think that the Trump campaign got it boiling again. You walk around town, you see a ton of Trump signs, Lou signs, there are some Confederate flags hanging around town that I don’t ever remember seeing – at least that many of them – growing up.”

In a Senate race that has become increasingly ugly over the past few months, Casey’s campaign has accused Barletta as being “more interested in scoring political points with anti-immigrant extremists than actually reforming our immigration system”. The Democrat has also drawn attention to Barletta’s position on the board of the Federation for American Immigration Reform – an organization which the Southern Poverty Law Center describes as an “extremist group” with links to white supremacists – and criticized his appearance with Farage.

Lou Barletta, the former mayor of Hazleton, Pennsylvania, stands by the anti-immigrant views he had as mayor. Photograph: Matt Rourke/AP

For his part, Barletta has seemed undeterred by the criticism.

“When Bob Casey disagrees with someone, he avoids the issue and calls them a hater,” said a spokesman for the Barletta campaign.

“The people of Pennsylvania have grown tired of Bob Casey’s attempts to divide us rather than engage in serious debate on the most important issues facing our country, including illegal immigration.”

Just as Trump has stayed true to the anti-immigrant views he espoused during his campaign, Barletta has stuck with the beliefs he held as mayor of Hazleton.

The way that the congressman and president have mirrored each other over immigration was highlighted in a letter Barletta sent to prospective voters in February.

“With every day that passes, more Americans are killed or victimized by violent criminal aliens,” Barletta’s mailer warned, in language that could have come straight from the mouth of Trump.

In a more explicit effort to link his beliefs, forged and enacted as mayor of Hazleton, with Trump’s, forged over the course of his presidential campaign and now being enacted across the US, Barletta had even included an endorsement from the president.

“Lou Barletta. Great guy. He’s running. He was an incredible congressman. And I think you’re going to have a tremendous surge for Lou Barletta,” the quote from Trump read.