Laravel validation attributes “nice names”

后端 未结 10 1799
[愿得一人]
[愿得一人] 2020-12-02 05:41

I\'m trying to use the validation attributes in \"language > {language} > validation.php\", to replace the :attribute name (input name) for a proper to read name (example: f

10条回答
  •  盖世英雄少女心
    2020-12-02 06:36

    In the "attributes" array the key is the input name and the value is the string you want to show in the message.

    An example if you have an input like this

     
    

    The array (in the validation.php file) should be

     'attributes' => array(
        'first-name' => 'Voornaam'),
    

    I tried the same thing and it works great. Hope this helps.

    EDIT

    Also I am noticing you don't pass a parameter to $errors->has() so maybe that's the problem.

    To fix this check out in the controller if you have a code like this

    return Redirect::route('page')->withErrors(array('register' => $validator));
    

    then you have to pass to the has() method the "register" key (or whatever you are using) like this

    @if($errors->has('register')
    .... //code here
    @endif
    

    Another way to display error messages is the following one which I prefer (I use Twitter Bootstrap for the design but of course you can change those with your own design)

     @if (isset($errors) and count($errors->all()) > 0)
     

    Problem!

      @foreach ($errors->all('
    • :message
    • ') as $message) {{ $message }} @endforeach

提交回复
热议问题