1

I know this is the duplicate question.There are so many solutions for this problem,but unfortunately nothing is working for me.I checked-

Laravel 5.2 form validation not showing errors?

Laravel 5.2 -> Validation Errors not appearing

ErrorBag is always empty in Laravel 5.2 and more...

i am using lavavel 5.2.29 and which things are doing to resolve this errors these are already doing in it. my routes, kernel are already looks like other solutions. In kernel.php

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

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],

        'api' => [
            'throttle:60,1',
        ],
    ];

IN Routes.php

Route::group(['middleware' => ['web']], function () {
    Route::get('/','IndexController@index');
    Route::get('user/','UserController@showProfile');
    Route::match(["get","post"],"user/register",'UserController@register');
    Route::match(["get","post"],"user/login",'UserController@login');
});

In user controller -

 $this->validate($this->Request,User::$add_user_rules);
$user_data = Input::all();
$user_data['username'] = explode('@',$user_data["email"])[0];
if(User::create($user_data)){
  $this->Request->session()->flash('success', 'Your account has been successfully created. Now please check your email to activate your account.');
  }else{
     $this->Request->session()->flash('error', 'Oops.. Something went wrong. Please try again !');
  }
return redirect("user/register");

and the rules are in user model -

public static $add_user_rules = [
        'first_name' => 'required|alpha_dash',
        'last_name' => 'alpha_dash',
        'email' => 'required|email|unique:users',
        'password' => 'required',
        "cn_password" => "required|same:password",
    ];

and last, this is i am using to show errors on blade -

@if (count($errors) > 0)
<div class="alert-message error">
    <div><span>Error !</span><br>
        @foreach ($errors->all() as $error)
        <p>{{ $error }}</p>
        @endforeach
    </div>

</div>
@endif

Now whats is missing in this code. Any error message is not showing. And one more thing, if i put the routes outside the middleware web everything works perfect.

Community
  • 1
  • 1
Jitendra
  • 558
  • 8
  • 23

1 Answers1

1

Now in the web middleware group by default in Laravel latest version 5.2**. If you have explicitly specified this middleware group inside your app\Http\routes.php file, you should remove it and that should resolve your issue.

Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72