Undefined variable: errors — Laravel 5.2

后端 未结 6 1276
不知归路
不知归路 2021-02-05 18:28

I am new in Laravel and using laravel version 5.2.

I created a controller and request named as ArticlesController and CreateArticleRequest

相关标签:
6条回答
  • 2021-02-05 18:38

    Posting this as it might be useful for others,

    As Praveen mentioned in 1st solution, in your Kernel.php file(app/Http/Kernel.php) move \Illuminate\View\Middleware\ShareErrorsFromSession::class from $middlewareGroups to protected $middleware property, but the same will start throwing the error "Session store not set on request",

    to resolve this move \Illuminate\Session\Middleware\StartSession::class, to $middleware property as well.

    0 讨论(0)
  • 2021-02-05 18:39

    Just cut all your routes from routes.php file and paste it between the middleware group 'web', just like this:

    Routes file

    0 讨论(0)
  • 2021-02-05 18:39

    With this code, you can catch errors and display them :

    @if ($errors->any())
     <div class='alert alert-danger'>
      @foreach ( $errors->all() as $error )
       <p>{{ $error }}</p>
      @endforeach
     </div>
    @endif
    
    0 讨论(0)
  • 2021-02-05 18:51

    This is a breaking problem with the 5.2 upgrade. What's happening is the middleware which is responsible for making that errors variable available to all your views is not being utilized because it was moved from the global middleware to the web middleware group.

    There are two ways to fix this:

    1. In your kernel.php file(app/Http/Kernel.php), you can move the middleware \Illuminate\View\Middleware\ShareErrorsFromSession::class back to the protected $middleware property.

    2. Wrap all your web routes with a route group and apply the web middleware to them:

      Route::group(['middleware' => 'web'], function() {
          // Place all your web routes here...(Cut all `Route` which are define in `Route file`, paste here) 
      });
      

    Copied from this post Laravel 5.2 $errors not appearing in Blade

    0 讨论(0)
  • 2021-02-05 18:54

    For 5.2, simply move the the routes that have the errors variable to middleware group

    0 讨论(0)
  • 2021-02-05 18:58

    This happens because the file below is not updated in the composer update process, so doesn't have the mapWebRoutes method implemented.

    app/Providers/RouteServiceProvider.php
    

    Copy this file over from a fresh install and it will work. Better, follow the upgrade path on the docs.

    0 讨论(0)
提交回复
热议问题