The only times I was really happy and motivated at work was when I was working within a team where we were really friends
Ditto!
A business is made of employees, but the employees are not the business. Sometimes that means decisions have to be made in favor (sometimes arguably) of the business over you.
Understanding the ephemerality of the situation can help you appreciate when it's going well and the people you work with, while helping you be prepared if and when something happens. Hopefully you will have gained a lot more experience, a bigger network of good friends, and have a decent nest egg to take you to the next job.