A laser capable of shooting down enemy drones and missiles will be on Royal Navy warships by 2027 amid the growing threat of conflicts in Ukraine and Gaza.