Rotate GameObject when moving it with rigidbody

I have this code to move my player:

         var x = Input.GetAxisRaw("Horizontal");
         var z = Input.GetAxisRaw("Vertical")

    rb.velocity = new Vector3(x * speed, rb.velocity.y,z * speed);

But its not working well. When I press “d” he moves up and when I press “a” he moves down. Its the same with w and s. He moves right and left. So that is the first thing. The major thing is that the gameobject is not rotating to the direct he is moving.

    transform.Rotate(0, x, 0);
    transform.Translate(0, 0, z);

with this it worked perfectly, but with that I could pass through walls though. Could you help me?

the rigidbody.velocity is the property that handles linear velocity only, you need to use angularVelocity for the x axis there