0

I have a simple piece of code that I would like to use inside the blade template:

@if($errors->has())
      @foreach ($errors->all() as $error)
            <div>{{ $error }}</div>
     @endforeach
@endif

However in order to use $errors, I read somewhere that I need to use web middleware so I set that as well for the route:

'middleware' => ['web']

and added:

$app->register(Illuminate\Session\Middleware\StartSession::class);
$app->register(Illuminate\View\Middleware\ShareErrorsFromSession::class);

to the app.php

But now, when I open this route, I'm getting this error:

lumen.ERROR: exception 'ErrorException' with message 'Argument 1 passed to Illuminate\Session\Middleware\StartSession::__construct() must be an instance of Illuminate\Session\SessionManager, instance of Laravel\Lumen\Application given
Zed
  • 5,683
  • 11
  • 49
  • 81
  • Are you using laravel 5.2? – Latheesan Mar 01 '16 at 10:31
  • Possible duplicate of: http://stackoverflow.com/questions/34438463/laravel-5-2-errors-not-appearing-in-blade – Latheesan Mar 01 '16 at 10:36
  • It is 5.1.I tried to follow some of the answers from the linked thread, it seems that the error is gone, but I'm getting now `exception 'ErrorException' with message 'Undefined variable: errors'` when I try to access $error in the view, it's like middleware is not included at all. – Zed Mar 01 '16 at 12:07

1 Answers1

2

The solution is to add this to app.php:

$app->middleware([ 
             Illuminate\Session\Middleware\StartSession::class,                        
             Illuminate\View\Middleware\ShareErrorsFromSession::class
]);
Zed
  • 5,683
  • 11
  • 49
  • 81