They called him a “jackass” and implied he was a child, but now some of President Donald Trump’s most vocal Republican antagonists on Capitol Hill are cozying up to the White House.

The reason is fairly simple: They have bills they want him to sign and policy they want to influence. And with Trump, a man who is so receptive to praise, in the White House, Republicans have learned that the easiest way to get there is flattery.

For some, that has meant overcoming nasty public spats to gain the president’s ear. One of those senators is Tennessee’s Bob Corker, who in October called the White House an “adult day care center.” Exactly four months later, Corker tweeted in praise of Trump’s “strong leadership” in the immigration debate.

Corker said he has resumed working with Trump. “Probably from November 1st on [...] we’ve talked about multiple issues, whether it’s Iran or tax issues,” Corker, the chair of the Foreign Relations Committee, told BuzzFeed News on Friday. “So there’s been a close interaction all the way through. People haven’t known that, but it’s been occurring ever since.”

Corker also insists his problem was never with the White House as a whole; rather, it was a “kerfuffle” and “one-on-one issue” with Trump, and he says he continued to communicate with others in the administration.

“One thing about the administration that’s different from administrations I’ve worked with in the past, they almost use the House and Senate as a board of directors,” Corker said. “I mean, if you’ll notice, they’ve got people over there non-stop on pertinent issues.”

Sen. Lindsey Graham, the lawmaker who called Trump a “jackass” in 2015, was one of Trump’s fiercest critics before the presidential election (in which Graham himself was, briefly, a candidate) but has since taking to regularly golfing with and defending the president on cable news. He has taken heat for Trump in recent months during times of controversy, particularly last December, when Graham criticized the media for its “endless attempt to label the guy as some kind of kook,” despite calling Trump the same thing the year before.

“There is a general agreement among Republicans in Washington that this president is uniquely susceptible to flattery,” said a Republican strategist who formerly served as a senior aide in the Senate. “It’s no secret that he enjoys the praise of others, and the question is whether that translates into favorable outcomes for the flatterers, and I think that the record here is uneven, but favorable enough that people view it as worth a shot.”

But the strategy a senator adopts to deal with Trump is far from a binary decision, one Republican Senate aide said. “For a lot of people in the media, Republicans must be either #MAGA4evah or #VivaResistance, end of story,” the aide said. “But dealing with Trump is much more nuanced than that. You have to deal with Trump on an issue by issue by basis. Praise him when he does something specific you like. Ignore him when he does something bad that doesn’t really affect you. Push back when he says something you disagree with about something you care about.”

Recent flare ups between the GOP senators and the Trump administration highlight the sometimes unsuccessful gamble Republican lawmakers make when they attempt to appease an unorthodox president in the hopes of advancing their priorities, however.

For Graham, last week marked a crack in the evolving relationship between the South Carolina senator and the White House. Graham’s rapprochement with the president has yet to pay off when it comes to immigration, as evidenced by Friday’s failure in the Senate to pass a bill to protect DREAMers and strengthen border security.

Graham was one of more than 20 senators who met for weeks to try to hammer out an immigration deal and came up with a bipartisan proposal that appeared to be gaining steam — only for Trump’s Department of Homeland Security and an unnamed White House official to slam it hours before the Senate voted on the bill. White House Press Secretary Sarah Huckabee Sanders also said in a statement that the president could veto the bill.

"There are a bunch of Republicans that would vote for this bipartisan compromise if the president would bless it,” Graham said on Friday after an anonymous White House official told reporters the bill was “spectacularly poorly drafted” and “reckless.” The official went on to repeatedly attack Graham personally on the call with reporters, but would not agree to attach his name to those remarks.

“If you don't like this bill, fine, tell me what you like, but all these veto threats, and bombastic rhetoric coming out of the White House against 18 or 20 senators that are trying to solve a problem is not helpful," Graham said.

Ultimately, the Senate failed to pass any of the four proposed bills — including one supported by Trump — on Friday, leaving the future of DREAMers and funding for Trump’s long-desired southern border in limbo.

Graham, according to the Republican strategist, “makes a very public showing of their friendship and says a lot of complimentary things about the president,” but “they’re not in the same place on immigration.”

“It’s probably worth buttering the president up if you want a legislative outcome, but it’s no guarantee of a result,” the strategist said.

Iowa Sen. Chuck Grassley, the chairman of the Senate Judiciary Committee, faced similar disappointment last week when the administration said it would not support a bipartisan bill he co-authored to reform the criminal justice system, despite his efforts to help the administration confirm controversial judicial nominees and shield it from Democrats’ demands in the Russia investigation.

The day before the committee was set to vote on the legislation, Attorney General Jeff Sessions sent a letter to Grassley blasting the bill, saying that passing it would be a “grave error.” Grassley tweeted that he was “incensed,” later saying that he was “really irritated” that Sessions would send the letter considering he helped Sessions get through a difficult confirmation process and defended Sessions when Trump was considering firing him.

“And worse yet, I just heard this morning, that maybe this letter went through [the Office of Management and Budget], so the White House approves of it,” Grassley said before the committee vote. “For the very same reasons that I’ve done things trying to help an administration to be successful, if they’re involved in this letter, that also irritates me.”

Asked whether it’s worth placating the president to advance policy and legislative goals considering the recent roadblocks Graham and Grassley have faced, Corker pointed to the Trump administration’s high level of engagement with Congress.

“They listen a great deal; they listen to a lot of people, ok?” Corker said when asked if lawmakers can wield strong influence over the Trump administration. “I mean they reach out and talk to people on the phone all the time.”

One of those who seems to have mastered the ability to both praise and distance himself from the president is Senate Majority Leader Mitch McConnell, who made no secret of his dislike for Trump before the election, but has since worked with the president on a number of issues, including passing tax reform, confirming a new Supreme Court justice, and repealing regulations disliked by Republicans.

Though there have been significant bumps, such as Trump’s public criticisms of McConnell last summer after the Senate failed to pass a bill to repeal the Affordable Care Act, McConnell has often been silent when negative headlines embroil the administration, offering rare but often light criticisms, and vocally supporting the president when the pair’s thinking aligns.

McConnell is pragmatic, the Republican strategist said, and has “sort of put on a clinic in distinguishing the important from the unimportant in going after those goals.”

But the strategy for each senator varies and depends on a range of elements, such as their election cycle and legislative goals. For someone like Arizona Sen. Jeff Flake, who comes from a state Trump won but isn’t running for reelection himself, there is more freedom to speak candidly about the president. But others who are facing reelection in 2018 and want to pass bills, such as Nevada Sen. Dean Heller, “are focused on identifying issues that they support that the president also supports, and then not unnecessarily provoking him,” the strategist said.

“This president is not broadly popular but he’s extremely popular among a certain segment of the party, so that presents a problem for senators who are in cycle,” the strategist said, noting Trump’s low overall approval rating, which has hovered around 40%.

It’s anyone’s guess, though, as to how the various strategies to deal with this president ultimately pan out, the Republican Senate aide said. “Every office holder is making these calculations on a daily basis and I don’t think we’ll know who made these decisions the best till Trump is gone."