It's either your charger or your cable which is giving trouble. It's also recommended to clean out your charging socket of the phone with a toothpick. But be gentle though. Dust in the socket prevents your cable to be plugged completely in the phone. Removing dust will solve this
I would for sure take it to the Apple store and look in to getting a warranty repair. Apple is very good about these things. You can make an appointment before you go.....
Be sure you use only a certified lightning cable. I would use an Apple charger/adapter. And, like has been stated, be sure the charging port is clean. If all that fails, take it to Apple.