Laravel 5.5 Login errors not showing up
Try to remove Session::get('errors')
from your if
statement in login.blade.php
@if(count( $errors ) > 0)
@foreach ($errors->all() as $error)
<h1>{{ $error }}</h1>
@endforeach
@endif
ShareErrorsFromSession
middleware, which is provided by the web middleware group is responsible for $error
view variable so it will always be defined (link here)
[UPDATE]
And as @Ohgodwhy pointed, you need to use @if ($errors->any())
Example
So in your case it will be:
@if($errors->any())
@foreach ($errors->all() as $error)
<h1>{{ $error }}</h1>
@endforeach
@endif
Ok, after a few hours I finally found it! I created a Laravel project from scratch and made a diff to find the culprit:
In app/Http/Kernel.php, make sure to get rid of the StartSession middleware:
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Session\Middleware\StartSession::class, // <-- Remove this
];
Explanation: I had it there because I read that I had to put it as a middleware (if I wasn't using the Route::group(['middleware' =>'web']
wrapper in my web.php), I think that I forgot it there. I think that putting it there and using the wrapper in web.php somehow truncate the error session before it gets to the view.
Put,
Auth::routes();
Inside middleware group.
Web middleware starts the session. If you are writing any route outside that middleware group then you can not access the session.