The most humane and long-term solution to discourage foxes is to remove or prevent access to the things that are attracting them to the area, like food and shelter.
Barriers, such as fencing or prickly plants, and chemical repellents that are approved for use with foxes, may discourage them from coming into a garden. Repellents are available from garden centres or hardware stores, but care must be taken to follow the instructions closely as each product is prepared and approved for use against certain animals in a particular way.