One solution to this issue could be to store the CSRF token in a cookie instead of in the session. This way, even if the user switches tabs, the CSRF token will still be available in the cookie and can be used to make AJAX requests. You can use the csrf_token function in Laravel to generate the token, and then store it in a cookie using JavaScript.
<meta name="csrf-token" content="{{ csrf_token() }}">
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
document.cookie = `XSRF-TOKEN=${csrfToken}`;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = csrfToken;
When making an AJAX request, Laravel will automatically look for the CSRF token in the X-CSRF-TOKEN header or in the _token input value. By storing the token in a cookie, it will persist even if the user switches tabs.
In case you want to keep storing the token in the session, you may want to consider storing the session in a shared cache like Memcached or Redis, which will allow multiple instances of your application to share the same session data. This way, even if the user is directed to a different pod, they will still have the same session and the CSRF token will not be invalidated.