Back to Error Center
Session store not set on request
Error Message
RuntimeException: Session store not set on request.
Cause
Trying to access session data without a session driver configured or without the web middleware applied to the route.
Solution
Ensure the web middleware is applied to routes that need sessions. Configure SESSION_DRIVER in .env. For API routes, use token-based auth instead.
Code Example
Fix
// Ensure web middleware for session routes
Route::middleware(['web'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index']);
});
// .env
SESSION_DRIVER=file
SESSION_LIFETIME=120
// For API routes, use Sanctum
Route::middleware(['auth:sanctum'])->group(function () {
Route::get('/user', fn (Request $r) => $r->user());
});
Debugging Steps
- Check SESSION_DRIVER in .env
- Verify web middleware is applied
- Check if the session file/directory exists
- Verify session permissions (storage/framework/sessions)
Prevention
Always apply the web middleware for routes using sessions. Configure session driver appropriately for each environment.