Skip to content

Debug: Session Not Saving

The log shows "session_before":null, which means the session is not being saved when you click the switcher.

Complete logs have been added to track the entire process:

  • βœ… When route is called
  • βœ… What locale is requested
  • βœ… Session state before and after
  • βœ… When method is called
  • βœ… If session saves correctly
  • βœ… Session ID and driver used
  • βœ… If it finds locale in session
  • βœ… Final locale decision
Terminal window
# In your Laravel project
echo "" > storage/logs/laravel.log
  1. Go to your Filament panel
  2. Click the language switcher
  3. Observe if there’s a redirect
Terminal window
tail -f storage/logs/laravel.log
Language switch route called {"requested_locale":"en",...}
LanguageSwitcher::setLocale called {"requested_locale":"en",...}
LanguageSwitcher::setLocale completed {"session_after":"en",...}
Language switch result {"success":true,"session_after":"en"}
SetLocale: Using session locale {"session_locale":"en"}
Language switch route called {"requested_locale":"en",...}
LanguageSwitcher::setLocale called {"requested_locale":"en",...}
LanguageSwitcher::setLocale completed {"session_after":null,...} ← PROBLEM
Language switch result {"success":true,"session_after":null} ← PROBLEM
SetLocale: Final locale decision {"session_before":null,...} ← PROBLEM

Check your config/session.php:

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => env('SESSION_LIFETIME', 120),
'path' => env('SESSION_PATH', '/'),
'domain' => env('SESSION_DOMAIN', null),

Verify that StartSession is in web middleware group.

Terminal window
# Check storage/framework/sessions permissions
ls -la storage/framework/sessions/
Terminal window
php artisan route:list | grep language

Add at the beginning of the route:

if (!session()->isStarted()) {
session()->start();
}
Terminal window
php artisan config:show session.driver

If session fails, use cookie:

// In setLocale()
Session::put('locale', $locale);
cookie()->queue('locale', $locale, 525600); // 1 year

Share this log data:

  1. Is route called? β†’ Language switch route called
  2. Is setLocale executed? β†’ LanguageSwitcher::setLocale called
  3. Is it saved in session? β†’ "session_after":"en" vs "session_after":null
  4. What session driver? β†’ "session_driver":"file"
  5. Is there session ID? β†’ "session_id":"xyz123"

With this information we can identify exactly where the process fails.

After debugging you should see:

  • βœ… Route executes correctly
  • βœ… Session saves: "session_after":"en"
  • βœ… Middleware reads session: "session_locale":"en"
  • βœ… Language change works