Each have their own merits and drawbacks, so there's a time and a place for both.
Both are being researched for the US Navy as a replacement to our current loaded munitions.
The advantages of a railgun over current cannons is that the ammunition is much safer to transport, as the old problem it provides is that if you drop it, you might dent it up a bit, as opposed to risking explosions. It's also going to be heavy, so you might hurt yourself a bit.
The laser on the other hand removes those problems, but suffers with issues mentioned before, diffusion, refraction, and other long range issues. At shorter ranges the laser becomes the safer option.