我加载了一个包“Vue Laravel Validator”以在vue中验证。 例如:
<input id="name" v-validate="'min:6|max:46|required'" type="text" name="title" class="form-control" required v-model="title">
<div class="help-block with-errors" v-show="errors.has('title')">В название:
<a> {{ errors.first('title') }}</a>
</div>
显示错误:The title field must be at least 6 characters.
如何更改错误文本?
例如:"the title only 6 characters"
答案 0 :(得分:1)
您可以在Laravel验证(服务器端)
中设置自定义消息public function save(Request $request){
$validation = $this->validate($request, [
'name' => 'required|min:3|max:32'
],[
'name.required' => 'Name is required',
'name.min' => 'Name should be greater than 3 characters',
'name.max' => 'Name should be less than 32 characters'
]);
if($validation->fails()){
return response()->json($validation->errors()->all());
}
}