Why does my dog eat grass? And when is it not safe for them?

So why does my dog eat the grass?