I'm a long-time vegetarian with relatively recent gluten intolerance so I have some experience of this.
The first thing to do is be open about it. With allergies it's relatively easy, as few people will argue with them.
With other things, it is IME easier if you have a public reason, but almost always I've been able to get acceptance from my workplace. But public reason I mean "I'm Jewish, that's not kosher" or "I'm an environmentalist, I don't eat meat". Some people prefer not to say why (some religious people, people with emotional reasons "I don't eat cute things") or just don't want to deal with the inevitable disparagement that comes with the reasons. Some people will take issue with either your actions or your beliefs.
Unfortunately if you don't give reasons some people will just ignore your preference or keep badgering at you to find out why, exactly, you don't do or eat whatever it is. I've found that just firmly repeating "none of your business" works, or you can be more polite if you like.
The second level is to approach management of the organisers directly. This is more a formal complaint action, where you should prepare a clear description of the events, the problem, and what resolution you would like. Be ready for them to go away and check your facts. The times I've done this have been as a result of serious stupidity (a mandatory company event in a remote area where I would literally have nothing to eat for two days, as we were forbidden to bring our own food), and that was resolved very quickly by the company owner (suitable food was provided).
For less serious stuff, I often switch to publicly telling everyone who asks that I can't go because there's no food I can eat. This sometimes fixes the problem through embarrassing the organisers, other times people just accept it. With difficulty at times.
Very rarely I find myself forced to attend something where there's nothing I can eat. In which case I just accept it. I went to the first Xmas dinner at my new job despite not being able to eat, because it was important to management. I ended up having a 10 minute discussion with the boss's wife who was very keen to have the chef make something for me, but eventually I talked them out of it. That was unpleasant, but such is life. I doubt I'll attend another one of those, because it turns out that the manager who was most emphatic that I had to go is full of it and I could probably have got away with not going.