(CNN) The California Supreme Court on Thursday unanimously ruled the state's new law that requires presidential candidates to disclose their tax returns for the previous five years to get on the ballot is invalid.

The ruling is a win for President Donald Trump, who is resisting efforts to turn over his tax returns.

California Gov. Gavin Newsom signed the law in July, and it was immediately challenged in court by the President, Republican voters, the Republican National Committee and the Republican Party of California.

Chief Justice Tani Gorre Cantil-Sakauye wrote in the opinion that the law "is in conflict with the Constitution's specification of an inclusive open presidential primary ballot."

"The Legislature may well be correct that a presidential candidate's income tax returns could provide California voters with important information," Cantil-Sakauye wrote. But, she argues, the state Constitution says that "ultimately, it is the voters who must decide whether the refusal of a 'recognized candidate throughout the nation or throughout California for the office of President of the United States' to make such information available to the public will have consequences at the ballot box."

Read More