0

I'm trying the suggestions for getting validation working on a new Laravel 5.2 install on Bitnami WAMP and having no luck. I have tried both suggestions that are given at Laravel 5.2 $errors not appearing in Blade among other places with the following errors returned from pages that have not even begun using validation.

When I try putting my working route (app/http/routes.php) on Route::group(['middleware' => ['web']], function () {... etc. as follows:

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
];

I get the following error messegaes:

+ RuntimeException in Request.php line 852: Session store not set on request.
+ in Request.php line 852 at Request->session() 
+ in ShareErrorsFromSession.php line 42
+ at ShareErrorsFromSession->handle(object(Request), object(Closure))
+ at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
+ at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
+ at Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
+ at CheckForMaintenanceMode->handle(object(Request), object(Closure))
+ at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
+ at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
+ at Pipeline->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
+ at Pipeline->then(object(Closure)) in Kernel.php line 132
+ at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
+ at Kernel->handle(object(Request)) in index.php line 54

When I try moving my protected $middlewareGroups web (app/Http/Kernel.php) on protected $middleware = [], as follows:

Route::group(['middleware' => 'web'], function() {
    Route::resource('country', 'Region\CountryController');
});

I get the error messages:

+ RuntimeException in EncryptionServiceProvider.php line 31: No supported encrypter found. The cipher and / or key length are invalid.
+ in EncryptionServiceProvider.php line 31
+ at EncryptionServiceProvider->Illuminate\Encryption{closure}(object(Application), array()) in Container.php line 735
+ at Container->build(object(Closure), array()) in Container.php line 633 at Container->make('encrypter', array()) in Application.php line 674
+ at Application->make('Illuminate\Contracts\Encryption\Encrypter') in Container.php line 853
+ at Container->resolveClass(object(ReflectionParameter)) in Container.php line 808
+ at Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 779
+ at Container->build('App\Http\Middleware\EncryptCookies', array()) in Container.php line 633
+ at Container->make('App\Http\Middleware\EncryptCookies', array()) in Application.php line 674
+ at Application->make('App\Http\Middleware\EncryptCookies') in Pipeline.php line 123
+ at Pipeline->Illuminate\Pipeline{closure}(object(Request))
+ at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
+ at Pipeline->Illuminate\Routing{closure}(object(Request))
+ at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
+ at Pipeline->then(object(Closure)) in Router.php line 726
+ at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
+ at Router->dispatchToRoute(object(Request)) in Router.php line 675
+ at Router->dispatch(object(Request)) in Kernel.php line 246
+ at Kernel->Illuminate\Foundation\Http{closure}(object(Request))
+ at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
+ at Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
+ at CheckForMaintenanceMode->handle(object(Request), object(Closure))
+ at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
+ at Pipeline->Illuminate\Pipeline{closure}(object(Request))
+ at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
+ at Pipeline->Illuminate\Routing{closure}(object(Request))
+ at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
+ at Pipeline->then(object(Closure)) in Kernel.php line 132
+ at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
+ at Kernel->handle(object(Request)) in index.php line 54

These errors come up on a page that is not even asking for validation yet.

When I attempt to get $errors on a blade template that is redirected to after an update in the store method, $errors is not defined either.

Any help is welcome as I have been trying to solve this for several days now in a new Laravel 5.2 installation.

Thank you

Community
  • 1
  • 1
  • Have you generated a random `APP_KEY` in your `.env` file? – alepeino Mar 15 '16 at 14:17
  • Not yet. I'll attempt that now. – David Dodson Mar 15 '16 at 15:37
  • Alejandro THANK YOU!!!!! Although changing the kernel.php file still gave me the exact same results, the second method of using the middleware wrapper in the routes file did work. If you have any additional notes why generating the random APP_KEY affected validation, I would love to know more about why that worked. Regardless, THANK YOU AGAIN!!! – David Dodson Mar 15 '16 at 15:56

1 Answers1

1

(Posting it here as a formal answer)

The second way you mention is more convenient, applying middlewares (or middleware groups, as web is) in your routes definition.

The web group includes middlewares related to session and encrypting. Laravel uses the value of APP_KEY to encrypt all session data, and form inputs and validation errors are stored in the session.

At some point during the session access, Laravel tries to create en Encrypter object, which fails if the application key is not 32 characters long. I just found that reading the source code, but you just need to know that when you do the initial configuration of your application, your .env file should have a 32-long random string as APP_KEY. The Artisan command key:generate does that for you.

alepeino
  • 9,551
  • 3
  • 28
  • 48