Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:60:6

There has certainly been for you in them an excellent pattern for anyone whose hope is in Allah and the Last Day. And whoever turns away - then indeed, Allah is the Free of need, the Praiseworthy.  

Verily there is for you, O community of Muhammad (s) (laqad kāna lakum is the response to an implied oath) in them a good example, for those ˹of you˺ who (li-man kāna is an inclusive substitution for –kum ˹of lakum, ‘for you’˺ with the same preposition ˹li-˺ repeated) anticipate God and the Last Day, that is, ˹for those˺ who fear these two, or who expect reward or punishment. And whoever turns away, by befriending the disbelievers, ˹should know that˺ God is the Independent, ˹without need˺ of His creatures, the Worthy of Praise, to those who obey Him.
القرآن:٦٠:٦

لَقَدْ كَانَ لَكُمْ فِيهِمْ أُسْوَةٌ حَسَنَةٌ لِمَنْ كَانَ يَرْجُو اللَّهَ وَالْيَوْمَ الْآخِرَ ۚ وَمَنْ يَتَوَلَّ فَإِنَّ اللَّهَ هُوَ الْغَنِيُّ الْحَمِيدُ  

{لقد كان لكم} يا أمة محمد جواب قسم مقدر {فيهم أسوة حسنة لمن كان} بدل اشتمال من كم بإعادة الجار {يرجوا الله واليوم الآخر} أي يخافهما أو يظن الثواب والعقاب {ومن يتول} بأن يوالي الكفار {فإن الله هو الغني} عن خلقه {الحميد} لأهل طاعته.

See similar narrations below:

Collected by Qurʾān
quran:33:21

There has certainly been for you in the Messenger of Allah an excellent pattern for anyone whose hope is in Allah and the Last Day and ˹who˺ remembers Allah often.  

Verily there is for you a good example (read iswa or uswa) in the Messenger of God, to emulate in combat and in holding one’s ground ˹therein˺, for whoever (li-man substitutes for lakum, ‘for you’) hopes for ˹the encounter with˺ God, fears Him, and the Last Day, and remembers God often, in contrast to those who do not.
القرآن:٣٣:٢١

لَقَدْ كَانَ لَكُمْ فِي رَسُولِ اللَّهِ أُسْوَةٌ حَسَنَةٌ لِمَنْ كَانَ يَرْجُو اللَّهَ وَالْيَوْمَ الْآخِرَ وَذَكَرَ اللَّهَ كَثِيرًا  

{لقد كان لكم في رسول الله أسوة} بكسر الهمزة وضمها {حسنة} اقتداء به في القتال والثبات في مواطنه {لمن} بدل من لكم {كان يرجو الله} يخافه {واليوم الآخر وذكر الله كثيرا} بخلاف من ليس كذلك.