Home  >  Article  >  Backend Development  >  Why Does Laravel Throw a \"Session Store Not Set on Request\" Error in a New Project?

Why Does Laravel Throw a \"Session Store Not Set on Request\" Error in a New Project?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-03 03:21:02960browse

Why Does Laravel Throw a

Laravel "Session Store Not Set on Request" Issue

Question:

In a newly created Laravel project, when accessing login or register routes, an error occurs:

ErrorException in Request.php line 775:
Session store not set on request. (View: C:\Users\Matthew\Documents\test\resources\views\auth\register.blade.php)

Despite not modifying any core files and only adding routes and views, the issue persists.

Answer:

To use session state and CSRF protection, the web middleware must be applied to the affected routes. This is typically done by grouping the routes within a web middleware closure:

<code class="php">Route::group(['middleware' => ['web']], function () {
    // your routes here
});</code>

This ensures that the routes within the closure utilize the features provided by the web middleware, resolving the "Session Store Not Set on Request" error.

The above is the detailed content of Why Does Laravel Throw a \"Session Store Not Set on Request\" Error in a New Project?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn