You can back up messages on an iPhone to your iCloud account, or sync messages from your iPhone to your Mac.
If you're trying to recover texts or iMessages on iPhone, use iOS 16, Finder, iTunes, or iCloud to retrieve them.