Lasers are great for taking down incoming missiles, drones or small aircraft. But the current system, at only 30kW, is of no use against larger or hardened targets. Stepping up to a megawatt class laser is either going to require supercooled magnet arrays and large generation facilities for a free electron laser (and you will need liquid helium or possibly liquid nitrogen to keep them functional), or storage for chlorine and iodine as well as hydrogen and potassium hydroxides for a COIL laser (the hazardous nature of those substances adds even more issues).
Rail guns have their own issues. They need massive capacitor banks that can be very dangerous at full charge, or homopolar generators which would need to be massive for a naval sized rail gun. The high temperatures and EM fields at firing would cause any fuses to go off in HE rounds, so they would be limited to kinetic rounds only. That drastically reduces their usefulness. On top of that, each time the gun is fired, the rails are subjected to buckling forces, intense heat and part of the rails are blasted away as plasma. Each shot, your accuracy decreases, as well as your effective range and the kinetic hitting power. It is fine to have 'virtually unlimited' ammunition, but what use is that when you have a gun that you can only fire a few times before you have to change the barrel?
Sure, 'futuristic' weapons such as these look good on paper, when an Admiral is convincing politicians for a few hundred billion dollars, but I doubt they really will be replacing naval weapons for the forseeable future.