The various deterrents you can buy do work, but if you've got a big supply of fox food in your garden - and lots of other foxes nearby to provide competition for easier meals - then not much, apart from a reasonably assertive dog, is going to keep the foxes away.
If you can, harden your garden's perimeters - chicken wire on all the fences, close up any gaps - and lace it all with deterrents - then you need to secure the pens the animals live in. Chicken wire is fine, but both foxes and badgers dig, and dig well, so it needs to go under the pens as well.
We have neither foxes nor badgers because of having dogs, but if we go away for more than a week the foxes start nosing around the other livestock.