Setting campaigns in a non-traditional time periods?

For a campaign I am planning, I feel that it needs to be set in a time with at least semimodern technology and conveniences, (like maybe a train) along with magic. And in another campaign that I’m planning, there needs to be modern or even futuristic technology and conveniences, while still keeping the lore and awesomeness of magic in the campaign, or even merging the two into magitech. So the question I am asking is what advice might you have for doing that? How do you make technology work without taking away the power of magic? For instance, if I have a “laser gun” that has, let’s say 200 charges, and does relatively similar damage to magic missile, and is a common item, it then makes no sense to learn magic missile, because you can just get a laser gun. How do I make sure that magic is still a good option for players? I’m sorry I’m asking a dumb question, but I am a first-time DM right now.

Oh, by the way, to keep things simple, you can just reply in the form of looking at the magic missile dilemma.