The Prophet ﷺ was asked about a man who fights out of bravery, one who fights out of zeal for his people, and one who fights to be seen. The Messenger of Allah ﷺ replied, "Whoever fights so that the word of Allah may be supreme is fighting in the cause of Allah."
حدثنا محمد بن عبد الله بن نمير حدثنا أبو معاوية عن الأعمش عن شقيق
سئل النبي ﷺ عن الرجل يقاتل شجاعة ويقاتل حمية ويقاتل رياء فقال رسول الله ﷺ من قاتل لتكون كلمة الله هي العليا فهو في سبيل الله
Bukhari narrated it in the Book of Tawhid, Chapter on the saying of Allah the Exalted, "Our word has already preceded for Our messengers" [Saffat 37:171], no. 7458, from the hadith of Amash, through him.And Muslim narrated it in the Book of Emirate, Chapter on whoever fights so that the word of Allah may be supreme is fighting in the cause of Allah, no. 1904, from Muhammad bin Abdullah bin Numayr, through him.The hadith has other routes of transmission in both of their collections.