Laravel 5.3 return custom error message using $this->validate()

前端 未结 4 999
星月不相逢
星月不相逢 2020-12-05 14:09

How to return a custom error message using this format?

$this->validate($request, [
  \'thing\' => \'required\'
]);
4条回答
  •  醉梦人生
    2020-12-05 14:38

    https://laravel.com/docs/5.3/validation#working-with-error-messages

    $messages = [
        'required' => 'The :attribute field is required.',
    ];
    
    $validator = Validator::make($input, $rules, $messages);
    

    "In most cases, you will probably specify your custom messages in a language file instead of passing them directly to the Validator. To do so, add your messages to custom array in the resources/lang/xx/validation.php language file."

提交回复
热议问题