Laravel 5.2 validation errors not appearing

后端 未结 4 1187
名媛妹妹
名媛妹妹 2021-01-21 13:13

I am trying to get validation errors to show up in Laravel.

I have a UserController set up like so:



        
4条回答
  •  借酒劲吻你
    2021-01-21 13:24

    The errors block should be:

    @if (count($errors) > 0)
        
      @foreach ($errors->all() as $error)
    • {{ $error }}
    • @endforeach
    @endif

    Assuming you're using Bootstrap for the alerts.

    You also don't have $validator defined. You need to do something like this:

    $validator = Validator::make($request->all(), [
        'email' => 'required|unique:users|email|max:255',
    ]);
    

    Instead of $this->validate().

    That should do it.

提交回复
热议问题