Answer the question
In order to leave comments, you need to log in
Field validation with Laravel default value?
Just started getting to know Laravel. Tell me how to do it right in such a situation?
We fill out the form when adding an article to the database, check the fields,
$this->validate($request, [
'name' => 'required|unique:articles',
'body' => 'required|min:100',
'state' => ''
]);
Answer the question
In order to leave comments, you need to log in
Why should it come from the client if it's "default"? Obviously, if there is no field or it is empty, then the application should set the default value, i.e. This does not apply to validation.
If this state field is not set by the user, then remove it from the form request. If by "default" you mean that if the user leaves it blank, then the default value will be set, then in the rules, validate it like everyone else, just without required.
What does Laravel have to do with it? This is a matter of your competence, not a specific tool. You write at least on Laravel, even on Django, it doesn’t matter, the question is your knowledge
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question