Hagarty has been praised after images of his kind gesture went viral

At a time when police seem to be making the headlines for all the wrong reasons, it is a gentle reminder of all the good work officers do.

A 35-year veteran of the Chicago Police Department has been lauded online after an image of him buying a homeless man a Chipotle for lunch went viral.

Sergeant B Hagarty was buying himself a meal in the Mexican eatery on Friday when he noticed the man rooting in the bins outside and invited him in for some food.

Scroll down for video

Sergeant B Hagarty, a 35-year veteran of the Chicago Police Department, has been praised after images of him buying a Chipotle for a homeless man went viral

Passerby Rachel Mitchell watched as Sgt Hagarty knocked on the window before telling the man to order whatever he wanted.

In a Facebook post, Ms Mitchell said the pair waited in line together, ordered, and then shook hands before going their separate ways.

She wrote: 'Touched my heart so much, with all the cr** police are getting these days it reminds me there’s so much more good out there than anyone ever wants to give credit.

'If everyone did something simple like this every day the world would be a better place.'

Since uploading the post, along with two images of Sgt Hagarty and the homeless man together, it has been shared hundreds of thousands of times, attracting hundreds of comments.

Eventually it came to the attention of the Chicago Police Department, which uploaded its own post naming Sgt Hagarty and praising his actions.

A police spokesman wrote: 'He [Hagarty] was not aware that someone had captured the moment, a break in his day as he was finishing his lunch, while at work just yesterday.

'He did not think he had done anything out of the ordinary. He did not want to brag about what he had done.

Passerby Rachel Mitchell, who took the pictures, said the homeless man was going through the bin outside this Chipotle restaurant when Sgt Hagarty invited him inside and told him to order whatever he wanted

'As he walked out a young lady approached him and told him that he had made her day. Sergeant Hagarty said thank you and walked out.

'Sergeant Hagarty thinks that might be who posted his pics on [Facebook]. If that is you, thank you. Sergeant Hagarty will retire before the end of the year and will be missed.

'Sergeant Hagarty we thank you for leading the Chicago Police Department by example.'

Writing online, Facebook user John Govea Alonzo said: 'Many officers do hidden gestures on a daily basis.

'You just happened to see this one, and by an honorable man. I'm certain it won't be his last, may God bless and grant him safe tours till end of his watch.'

Charmaine Reyes added: 'Love this. It's wonderful to see such a beautiful moment captured in the midst of all this negativity surrounding our city.