In this episode, we focus on making language selection in our app actually work long-term by connecting it to the session. When a user chooses a different language from the dropdown, we want that choice to "stick" by storing it in the session rather than just updating things on the client.
Here's what we do step by step:
- First, we set up a new backend route and controller that accepts a POST request when the language is changed in the UI. We use Inertia's router to send this change from Vue to Laravel.
- In the controller, we make sure that only allowed language values (from our enum) are saved to the session. If the language is invalid, we fall back to the app's default.
- We write tests to make sure this all works: one test for valid language changes, one for when the user tries to select something invalid (like Spanish, if that wasn’t an option). The tests check that the session is getting the correct value each time.
By the end of this episode, we have the language preference saving to the session reliably, and we’re ready to move on to the next step: hooking up middleware so every request uses the user's chosen language.