How to display the related post from the same category?

I am displaying the related post using the below code but I am getting all the posts, except the current one because I don’t want to show the same post in the related post.

I have to show the related post from the same category. Can you check and help me what is the issue with the code?