Yusuf Eka Sayogana
Yusuf Eka Sayogana

Reputation: 401

How to add the parameter name in custom validation laravel

I want to ask about custom validation. I make validation for counting the word

Validator::extend('word_count', function($attribute, $value, $parameters, $validator) {

       return str_word_count($value) >= $parameters;

});

How can i give name to parameter so that i can use the parameter value in error message?

Upvotes: 0

Views: 132

Answers (1)

Rama Durai
Rama Durai

Reputation: 750

Based on your question, i will understand you care about the validation message.

If you are looking for validation message mean, you can use custom message like,

If you are using the request file means, there we can use

messages(){
   return [
    'word_count' => '....', //some message will be here,
   ];
}

If you are using controller means, then use like

return response()->json('...', 422);

or

here also you can use that above messages function.

I hope, it will help you.If any thing ask here.

Upvotes: 1

Related Questions