iPhone Camera app doesn't work but some other apps can still use it
I’ve seen this be a temporary situation.

Power off your phone - normal controlled shut down
Power it on - test camera app before you run any other app

If that fails, back up and restore the phone. I’ve not seen erase all content and settings fix this, but I always try that before I restore since it’s a lot faster and I’m about to reload a backup either way at that point.
Once you’re sure it’s not a software issue, then it’s time for a hardware repair or swap. Apple has replaced my camera module on that model phone and I was extremely satisfied with the results. Much cheaper than a new phone as well even if you pay for the repair instead of AppleCare or warranty.