3

--- Custom validation class (application/libraries/validator.php) ---

 class Validator extends Laravel\Validator {
    public function validate_passwdU($attribute, $value, $parameters){
        $r_uppercase    = '/[A-Z]/';  //Uppercase
        $default_min = 1;
        if(is_numeric($parameters[0])>=$default_min){
        $default_min = $parameters[0];
        }
        return (preg_match_all($r_uppercase,$value, $matches)>=$default_min);       
    }
}

--- application/language/en/validation.php ---

    "passwdU" => "The :attribute must be at least :size uppercase characters."

--- Controller ---

    $rules = array(
        'passwd' => 'required|min:8|passwdU:2'
    );

    $validation = Validator::make($input, $rules);

    if ($validation->fails())
    {
        return Redirect::to('URL')->with_errors($validation);
    }

--- Input ---

passwd = 11111111

--- View ---

<pre>
<?php print_r($errors); ?>
</pre>

--- Output ---

Laravel\Messages Object
(
    [messages] => Array
    (
        [passwd] => Array
            (
                [0] => validation.passwdU
            )

    )
    [format] => :message
)

Why didn't I get the message that I defined in Language file?

Laurence
  • 58,936
  • 21
  • 171
  • 212
Sophy SEM
  • 223
  • 5
  • 19

1 Answers1

0

Passing messages method to the view

return Redirect::to('login')
    ->withErrors($validator->messages())

and printing it with get method

{{ $errors->get('email') }}

worked for me:

The email field is required.
JackPoint
  • 4,031
  • 1
  • 30
  • 42
Sinan Eldem
  • 5,564
  • 3
  • 36
  • 37