0

I loaded a package "Vue Laravel Validator" to validate in vue. Example:

<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>

And display error: The title field must be at least 6 characters.
How can i change text in error? For example: "the title only 6 characters"

1 Answer 1

1

You can set custom message in Laravel validation (server side)

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());
  }
}
Sign up to request clarification or add additional context in comments.

5 Comments

exuce me , write in post controller this?
Yes, where you are using these form values
i used to use v-validate="" (in vue) , how can i send it (via controller) in vue?
Check again, I have edited code. It will validate and return JSON in case of errors if($validation->fails()){ return response()->json($validation->errors()->all()); }
If you really are using Vue-Laravel-Validator then it is doing an ajax post: github.com/MetinSeylan/Vue-Laravel-Validator/blob/master/src/… so Sateesh solution is correct. Unless you're using vee-validate, which is something else and not what was asked. I upvoted Sateesh solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.