PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 15, 2022

[FIXED] How to give Laravel 6 validation attributes a custom name for error message?

 November 15, 2022     forms, laravel, laravel-6, php, validation     No comments   

Issue

I am trying to change the way my errors display when my Laravel form is not filled in correctly. Currently, when I get an error. It displays like this.

name mag niet groter zijn dan 255 karakters.

Because this language is Dutch, I would like to change the 'name' attribute to 'naam'. I have tried to change the $attributesNames like this but unfortunately it did not work.

$attributeNames = [
   'name' => 'Naam'   
];

This is what my validation function currently looks like.

/**
 * @return array
 */
public function validateCampaign() {
    // name needs to render as 'Naam'

    return request()->validate([
        'name' => 'required|max:255',
    ]);
}

Solution

As it turns out. I needed to edit the 'attributes' array in my resources/lang/xx/validation.php file.

It turns out like this:

'attributes' => [
    'name' => 'Naam'
]


Answered By - Niels Bosman
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing