Hey i have this problem too every now and then. And i tried everything like software updates and bying new cable, but ofc nothing of that worked. But i later dropped it (from 30cm height ca) by accident and after that it charges again. So i have fix the problem with both my brothers and my phone, by gently hitting (not destroy it) 3-5 on the back where the charging port/battery is located, cause it seems to be a cable in there that has loose contact or something.
Idk of it helps you guys, but it might be an option :)