Practice this first, don't first-time it in a set - better to do a consistent SH single laser than SHDL sometimes and side-B sometimes.
There really isn't a trick, you just have to practice the muscle memory and timing.
Anyway, here's my technique:
If you're dashing away from where you want your laser to go, short hop with Y, flick the analog stick to the side you want to face,(if your controller has bad snapback this will be way harder) and slide from Y to B right as you leave the ground.
The timing for sliding Y to B should be the same regardless of what situation you're performing the SHDL in - there's just a 3 frame window to hit B the first time, and only the earliest timing can hit certain characters. If you're standing still, you have to slam the stick as soon as you press B. This is something that will only come with a lot of practice - when I started it took me months to learn how to SHDL.