The Scottish parliament unanimously passed legislation requiring the government to make period products available for free to those who cannot afford them.