It won't..
You have to talk to or punish the afghan govt or improve the afghan govt
This is something Pakistan has been doing for over half a century, our kindness has been seen as weakness countless times. They took advantage of our kindness and took the lives of many of our civllians. They celebrated our dead children with a smile on their face.
There is no singular solution to the problem. The solution is multi-pronged.
-Pakistan must work on making it's internal situation as stable as possible in terms of a competent, motivated national government that has the trust of the people.
- Monitor all NGOs, foreign organisations, "human rights" "minority rights" organisations through covert ISR, moles, get access to their material and speeches.
- Empower local capable counter-insurgency institutions like the FC and local police forces.
-Controlling and monitoring the influx of foreign refugees - especially those from the Afghan/Iran border.
- Maximum security and surveillance on the Afghan-Iranian borders. Get those fencing finished as soon as possible. Finish the forts construction as soon as possible.
- I would also go as far as passing a law which can get people charged for openly supporting banned terrorist organisations that have taken the lives of civillians.