1

I am working on Laravel spark application and the problem is that I can not display the validation errors.

Here is the code. Backend:

$validator = Validator::make($request->all(), [
        'email'     => 'email|unique:users,email',
        'password'  => 'min:8'
    ]);

    if ($validator->fails()) {

        return redirect('users/add')
            ->withErrors($validator)
            ->withInput();
    }

Frontend:

<div class="form-group">
                            <label for="password">Password</label>
                            <input type="password" name="password" class="form-control">
                          {{json_encode($errors)}}
                            @foreach ($errors->get('password') as $error)
                                <p class="checkbox help-block">
                                    <small>{{$error}}</small>
                                </p>
                            @endforeach
                        </div>

The thing is that I am sure that validation rules fail and have checked that. But the error variable is empty...

Samuel De Backer
  • 3,404
  • 2
  • 26
  • 37
naneri
  • 3,771
  • 2
  • 29
  • 53

1 Answers1

1

Check your laravel app/Providers/RouteServiceProvider.php this row

protected function mapWebRoutes(Router $router)
{
    $router->group([
        'namespace' => $this->namespace, 'middleware' => 'web',
    ], function ($router) {
        require app_path('Http/routes.php');
    });
}

If your code does not have this - 'middleware' => 'web'

You have to add this into your routing

Route::group([
    'middleware' => ['web'],
], function () {
    Route::get('some_action' , 'SomeController@some_action');
});
Vanya Avchyan
  • 880
  • 7
  • 24
  • It has all this stuff. What I had to do is to move " \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class," from web middleware to middleware. That just does not make any sense – naneri Jun 12 '16 at 19:28