With magnesium it's more the specific salts that are laxative. Like the oxide which is both a laxative and has a low bioavailability. Citrate in huge doses is used as a laxative too. On the other hand, I have good experience with the orotate. Lactate and gluconate should be good too.
Magnesium supplements have laxative effects as long as they are not absorbed. More bioavailable forms of magnesium do not exhibit laxative effects in normal dosages.
There are plenty of opioid analogues to decrease it safely.