Open plamenradev opened 1 year ago
When you use a custom format for DateTimer and it throws an validation exception - you need to return back the date value in such a format, that could be parsed by Carbon::parse(), so here is an ugly solution, but it works, just for letting you know the idea.
In UserRequest class overwrite the following function:
protected function failedValidation(Validator $validator): void
{
}
In Screen save method:
public function save(User $user, UserRequest $request)
{
$validator = Validator::make($request->input(), $request->rules());
if ($validator->fails()) {
$input = $request->input();
data_set($input, 'user.dob', Carbon::createFromFormat(config('app.date_format'), $request->input('user.dob'))->format('Y-m-d'));
return redirect(url()->previous())
->withInput($input)
->withErrors($validator->errors()->messages());
}
...
}
Describe the bug DateTimer with custom format throws exception if any other field is filled incorrect.
To Reproduce
Could not parse '22/03/2023': Failed to parse time string (22/03/2023) at position 0 (2): Unexpected character
Layout:
Screen save method:
UserRequest class:
Expected behavior Correct parsing the date
Server (please complete the following information):
Additional context The date_of_birth fields in the database has type
date
I tried to play with prepareForValidation() and failedValidation() methods in the UserRequest class, but it still throws an exception.