Answer the question
In order to leave comments, you need to log in
Why doesn't data go through validation in laravel?
The situation is the following. Arrives json sent via fetch.
Json is valid, everything is OK, but the validation does not pass, although the controller is called and the data is put in the database (there is a method in the code below). To make sure the controller runs, I reverted to dd and it came back.
None of the following options work
Do not talk about the fact that the data for verification is different, it was necessary to at least somehow check.
public function validator(Request $request)
{
$validator = Validator::make($request->all(), [
'first_name' => 'first_name|unique:users',
'last_name' => 'last_name|unique:users',
]);
$this->validate($request, [
'first_name' => 'required|unique:posts|max:255',
'last_name' => 'required', //required - обязательно для заполнения
'phone' => 'required|unique:user|min:11|max:11',
'document_number' => 'required|unique:user|min:10|max:10',
'password' => 'required|min:8',
]);
}
$this->validate($request, [
'first_name' => 'required|unique:posts|max:255',
'last_name' => 'required',
'phone' => 'required|unique:user|min:11|max:11',
'document_number' => 'required|unique:user|min:10|max:10',
'password' => 'required|min:8',
]);
Answer the question
In order to leave comments, you need to log in
To all Laravel martyrs)
Check how you submit the request. Because my problem was that I didn't deliver
'Accept': 'application/json'
fetch("/api/register", {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'Accept': 'application/json'
},
body: json
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question