The issue is that the session middleware is not being applied to the error pages. To fix this, you can add the session middleware to the $middleware property of the app/Http/Kernel.php file.
Here's an example of how to do this:
-
Open the
app/Http/Kernel.phpfile. -
Add the following line to the
$middlewareproperty:\Illuminate\Session\Middleware\StartSession::class,This will ensure that the session middleware is applied to all requests.
-
Save the file and try accessing the error page again.
Here's what the updated $middleware property should look like:
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
// ...
];
If you're still having issues, you can try adding the web middleware group to the $middlewareGroups property of the app/Http/Kernel.php file. This will ensure that the session middleware is applied to all requests that go through the web middleware group.
Here's an example of how to do this:
-
Open the
app/Http/Kernel.phpfile. -
Add the following line to the
$middlewareGroupsproperty:'web' => [ \Illuminate\Session\Middleware\StartSession::class, // ... ],This will ensure that the session middleware is applied to all requests that go through the
webmiddleware group. -
Save the file and try accessing the error page again.
Here's what the updated $middlewareGroups property should look like:
protected $middlewareGroups = [
'web' => [
\Illuminate\Session\Middleware\StartSession::class,
// ...
],
'api' => [
'throttle:60,1',
'auth:api',
],
];