Let's say Bob is severely underpaid but really loves his job, the short commuting distance, and his coworkers. But sadly none of these things make up for the fact that Bob is at least $15,000 underpaid and, as his family grows, has an increasing need for better wages and an increasing desire to feel monetarily compensated for his worth.
Bob spends some significant time job hunting and, after some time and several interviews, gets an offer from a company at the exact wage he wants. As a last effort, Bob goes to his current manager and asks for a wage but without mentioning the other company's offer; no reason to corner what is a relatively a good boss (who in the end has to report to people who make the salary decisions) into an ultimatum situation similar to, "Pay me more or I leave."
To his manager's delight (at being able to keep Bob) and to obviously Bob's as well, the pay raise has been green lit and everyone is happy! Bob respectfully turns down the alternate company's offer and things are well for a few weeks. But then, the powers that be decide to let Bob go for no reason known to Bob or his manager other then the stinginess of the company owners that lead Bob into job hunting in the first place. Now, Bob is out of a job and has to go back to job hunting. Not only has he already interviewed and turned down offers with companies, he has to start fresh and from a significantly less pool of companies to choose from (let's say Bob was really scoped in on staying local).
Is there a way Bob could have avoided this in the first place? Negotiating some sort of contract where he couldn't be fired just weeks after his raise and turning down other offers?
Note: Bob was not fired as a consequence of any action that he took. The owners simply decided they'd rather not pay him at the new salary.