It seems like the issue you're encountering is related to session data not persisting after a redirect when using Laravel Breeze's AuthenticatedSessionController. This could be due to a number of reasons, including session configuration issues or middleware affecting the session.
Here are some steps you can take to debug and potentially solve the issue:
-
Check Session Driver Configuration: Ensure that your
.envfile is configured to use a session driver that supports persistent sessions, such asfile,database,redis, etc.SESSION_DRIVER=file -
Middleware Order: The order of middleware in your
app/Http/Kernel.phpfile can affect sessions. Make sure that\Illuminate\Session\Middleware\StartSession::classis included in thewebmiddleware group and that it is not being overridden or removed by any custom middleware. -
Clear Cache and Config: Sometimes configuration values can be cached. Clear your configuration cache to ensure that the latest config values are being used.
php artisan config:clear php artisan cache:clear -
Session Flash Usage: When you use
->with()on a redirect, it utilizes the session's flash data. Ensure that you are not doing anything that could overwrite or flush the session before it is read, such as calling$request->session()->regenerate()after setting the flash message. -
Test Session Without Redirect: To isolate the issue, try setting a session value and returning a view directly instead of redirecting. This can help determine if the problem is with the session itself or the redirect process.
public function store(LoginRequest $request) { $request->authenticate(); $request->session()->put('success', 'You have successfully logged in!'); return view('dashboard.index'); // Temporarily return a view directly } -
Inspect Session Middleware: Laravel Breeze may use certain middleware that could affect sessions. Inspect the middleware applied to the routes in
routes/web.phpand ensure that thewebmiddleware group is being applied to your routes. -
Listen to Session Events: Laravel fires events when session data is saved. You can listen to these events to see if the session is being saved correctly.
\Illuminate\Support\Facades\Event::listen( 'Illuminate\Session\StoreSaved', function ($event) { logger('Session was saved', $event->session->all()); } ); -
Check for Overwritten Session: Ensure that no part of your application is inadvertently overwriting the session data after it has been set.
If after trying these steps the issue persists, it may be helpful to create a minimal example that reproduces the issue and share it with the community for further assistance. Additionally, you can check the Laravel Breeze repository for any open issues or discussions related to session handling.