This code is historically how laser were driven, but there have been issues recently. Over the last six months or so there have been complaints about quality of laser output posted to the forum when using the fan pins to drive the laser. Historically fan pins have been the way to drive the laser on an MPCNC, so either historically people have worked around the quality issues, or something has changed in recent versions of the firmware.
The solution to the quality issues has been to enable laser support in the firmware and use inline laser commands. Inline commands use an S parameter with G0, G1, G2 and G3 g-code commands to set the laser strength. Laser support is enabled in the Rambo 1.4 and the SKR Pro 1.2 versions of the Marlin firmware maintained by V1, but not the other V1 maintained versions.
There are a number of changes in Marlin’s configuration_Adv.h to enable inline laser support, so if you don’t have a Rambo or SKR Pro board, I would recommend doing a diff between your Marlin firmware and a V1 maintained version with the laser enabled. I posted one diff in this topic. I’m currently using Meld to do source code diffs. Also Ryan provides a g-code test file with inline commands in the first post of this topic .
Note you will need a P parameter to your M106 and M107 if you are using any fan pins but Fan0. For example, the Rambo board has three fan pin pairs.