It's not clear from your explanation whether the cable is slipping where it's attachedd or if the slack is coming from somewhere else. I'm going to start with the former.
In your photo, the cable is pinched between the bolt head and the washer below it. This setup has only a small flat surface area for gripping the cable, so it is easy for it to slip unless you tighten it so much that the cable is flattened. The proper routing is under the washer. The cable should lie in the groove that is just to the right of the washer. The groove helps ensure that the cable is secure and pulling from the correct angle. Disc brakes pull with a high leverage ratio, so it is easy to generate enough force to cause the cable to slide if it is not properly secured.
So, 1)loosen the bolt until the washer can be raised up enough to slide the cable beneath it.
2) pull the cable taut. Check that the end of the cable housing is seated properly at the brake lever.
3) tighten the bolt while keeping the cable taut. Make sure the bolt is very tight.
You may even need to move the lever arm slightly before tightening in order to get enough cable tension to brake properly. There should also be a pad position adjustment on the back side to adjust the position of the stationary pad.