This is quite common with pretty much anything using micro USB cables for power. The cables are prone to breaking internally, right behind the plug where the wires are soldered to the contacts. So first thing I'd do is try a new cable. If that doesn't work, then it could possibly be a problem with the charger or the port on the phone itself. So if a new cable doesn't work, then trying another charger (doesn't have to be an OEM as long as it's either rated 1.5A or is QC2.0 certified) would be next, and then lastly take the phone somewhere to be looked at.
If you try flexing the cable right behind the phone side plug, you may even start getting plug/unplug notices on the phone. This again leads to a cable issue, but is also likely to accelerate the problem.