You can put this solution on YOUR website! Apply the special case of sum/difference of cubes:
X^3+ Y^3 = (x + y)(X^2 - XY + Y^2 )
X^3 -^Y3 = (X - Y)(X^2 + XY + Y^2 )
.
In your case, it's the second one:
So
x^3-8/x+2
after factoring the numerator becomes:
(x+2)(x^2 -2x + 4)/(x+2)
canceling like-terms we get:
x^2 -2x + 4