Reputation: 173
I used laravel 5.1 for the previous project and I had no problem with it, but now I installed Laravel 5.2 and I got a problem with auth functionality so I use the following routes
Route::group(['middleware' => ['web']], function () {
Route::controllers([
"auth" => "Auth\AuthController",
"password" => "Auth\PasswordController"
]) ;
});
And it's ok I can see my auth form but when I send the form to the post route /auth/login
the session isn't set so I got the redirect but when I check if I logged in or not Auth::check()
I get false
Upvotes: 3
Views: 1155
Reputation: 26467
Not only the Authentication routes need to use the web
middleware group; all routes which require the functionality it provides need to use it too.
For example
Route::group(['middleware' => ['web']], function () {
Route::auth();
});
Route::get('example-1', function () {
dd(Auth::check()); // always will return false
});
Route::group(['middleware' => ['web']], function () {
Route::get('example-2', function () {
dd(Auth::check()); // works
});
});
The web middleware group simply collects and runs lots of middleware for you.
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
You'll notice StartSession::class
above. This means that for every request which you expect session data be available (for Auth and such) you'll need to have run this Middleware.
Either by using the web
group, or explicitly calling that middleware on the route/route groups you want.
Upvotes: 2