As the title my question is how they earn bitcoin by mining?
Is it only from the block rewards or they also get btc for the validation of transactions?
Thos are true what our friends said or answered in this discussion, and I think you OP also need to see an explanation of how Bitcoin Mining Works in animated form, so that it can easily make you understand how it really is. I saw a video about the explanation of Bitcoin Mining on the coingecko yt channel, maybe this can be a reference for you to understand more about the explanation:
Youtube - How Does Bitcoin Mining ACTUALLY Work?