Laravel Validation: check why validator failed

后端 未结 2 2016
长发绾君心
长发绾君心 2021-02-02 00:36

If there a way to check whether or not the validator failed specifically because of the unique rule?

$rules = array(
            \'email_address\' =         


        
2条回答
  •  误落风尘
    2021-02-02 00:54

    This will display an error and tell you what failed:

    Controller

    if($validation->fails()){
    
       return Redirect::back()->withErrors($validation)->withInput();
    }
    
    foreach($errors->all() as $error) {
      echo $error;
    }
    

    And in your blade template add this:

       @foreach($errors->all() as $error)
            
    {{$error}}
    @endforeach

    And that will return a message with whatever the error is. Email doesn't match. Field is required. Blah blah

    You can also remove that email array from the $message. The validator will handle all that for you. You only want to use that if you want custom messages.

    You can also try to var_dump this statement:

    var_dump($validation->errors()); die;

提交回复
热议问题