This also often is the case with these magnetic / magsafe like charging cables, because they are mostly made cheap Materials.
My advice would be:
Use a good (thick) charging cable (best case checked with an USB tester)
Don't use your phone while charging (to prevent wiggling)
Keep a charging level between 20-80% to keep battery healthy
Do not use fast charging whenever possible
If your phone is not charging, try to clean out the port Form dirt and dust (be careful)
If this is not fixing it, use wireless charging or let it repair by a professionalMore info on that? Because I use my laptop charger for everything, and since it's 65W, it's fast charging my phone
But for phones/mobile devices - Nowadays it's mostly smaller devices like headphones that might be vulnerable.
I have still observed fast chargers causing issues: My USB-C bluetooth headphones died after 2 months (could only hold battery for 30 minutes rather than 8 hours).
I started using another pair and was refreshed by the full 8 hours, thinking the first pair was a random issue.
But soon they were also running out after 6-7 hours.
I switched to the charger they came from an voila, they have kept 6-7 hours for months. Frustrating, because now I have to charge them for at least an hour or two, rather than 10 minutes, but at least they'll keep the battery health now.