"How will you judge?" He said: "I will judge according to what is in Allah's Book." He said: "If it is not in Allah's Book ?" He said: "Then with the Sunnah of the Messenger of Allah ﷺ." He said: "If it is not in the Sunnah of Messenger of Allah ﷺ?" He said: "I will give in my view." He said: "All praise is due to Allah, the One Who made the messenger of the Messenger of Allah suitable." (Using translation from Tirmidhī 1327)
أَنَّ النَّبِيَّ ﷺ لَمَّا بَعَثَهُ إِلَى الْيَمَنِ فَقَالَ كَيْفَ تَقْضِي؟ قَالَ أَقْضِي بِكِتَابِ اللهِ قَالَ فَإِنْ لَمْ يَكُنْ فِي كِتَابِ اللهِ قَالَ فَبِسُنَّةِ رَسُولِ اللهِ ﷺ قَالَ فَإِنْ لَمْ يَكُنْ فِي سُنَّةِ رَسُولِ اللهِ ﷺ قَالَ أَجْتَهِدُ رَأْيِي قَالَ فَقَالَ رَسُولُ اللهِ ﷺ الْحَمْدُ لِلَّهِ الَّذِي وَفَّقَ رَسُولَ رَسُولِ اللهِ