title: Custom validation messages in Laravel
body: <p>I am facing the problem with custom validation messages in laravel.
  I want to validate user create request, I have data as follows:</p>
  
  <blockquote>
    <p><code>first_name:Akhsay
    middle_name:R
    last_name:Doe
    gender:male
    miscellaneous:{"dob":"","birth_name":"xyz"}</code></p>
  </blockquote>
  
  <p>I have created the validation rules for creating a user in userCreateRequest.php as </p>
  
  <pre><code>public function rules()
  {
      return [
          'first_name' =&gt; 'required',
          'middle_name' =&gt; 'required',
          'last_name' =&gt; 'required',
          'gender' =&gt; 'required',
          'miscellaneous' =&gt; 'json|validate_misc_info',
      ];
  }
  
  /**
   * validation messages
   *
   * @return array
   */
  public function messages()
  {
      return [
          "first_name.required" =&gt; "First name is required.",
          "middle_name.required" =&gt; "Middle name is required.",
          "last_name.required" =&gt; "Last name is required.",
          "gender.required" =&gt; "Gender is required.",
          'miscellaneous.validate_misc_info' =&gt; '(**want to show specific error message here**)?'
      ];
  }
  </code></pre>
  
  <p>For miscellaneous information, I have created a custom validation service provider and in boot method of custom validator I have written the validation code as </p>
  
  <pre><code> Validator::extend('validate_misc_info',function($attribute, $value, $params, $validator) {
  
          $data = json_decode($value, true);
          $rules = [
              "dob" =&gt; "required|date",
              "birth_name" =&gt; "required|min:2|max:50",
          ];
          $messages= [
              "dob.required" =&gt; "Date of birth is required",
              "birth_name.required" =&gt; "Birth name is required",
          ];
  
          $validator = $data ? Validator::make($data, $rules, $messages) : false;
  
          if ($validator &amp;&amp; $validator-&gt;fails()) {
  
              return false;
          }
  
          return true;
      });
  </code></pre>
  
  <p>But when I 'm using this validation rule in userCreateRequest.php as</p>
  
  <pre><code>public function rules()
  {
      return [
          'first_name' =&gt; 'required',
          'middle_name' =&gt; 'required',
          'last_name' =&gt; 'required',
          'initial' =&gt; 'required',
          **'miscellaneous' =&gt; 'json|validate_misc_info',**
      ];
  }
  </code></pre>
  
  <p>Its showing me the error as </p>
  
  <pre><code>{
  "message": "The given data was invalid.",
  "errors": {
      "miscellaneous": [
          "validation.validate_misc_info"
      ]
  }
  </code></pre>
  
  <p>but I want to show a specific error message as</p>
  
  <pre><code>{
  "message": "The given data was invalid.",
  "errors": {
      "miscellaneous": [
          "Date of birth is required"
      ]
  }
  </code></pre>
  
  <p>Please help me.</p>