Answer the question
In order to leave comments, you need to log in
How to write validation?
I have a big form. The data from this form is stored in two tables. Part to one, part to another.
I see options:
One common validator. Then scatter each field according to the models
$validator = Validator::make();
$validator1->validate();
//...
$model1->update([
'field1_1' => $request->get('field1_1'),
// Дофига полей
]);
$model2->create([
'field2_1' => $request->get('field2_1'),
// Дофига полей
])
$validator1 = Validator::make();
$validator2 = Validator::make();
$data1 = $validator1->validate();
$data2 = $validator2->validate();
$model1->update($data1);
$model2->create($data2);
try {
$data = $validator1->validate();
} catch (ValidationException $e) {
return redirect()->back()->withErrors($validator1)->withInput();
}
try {
$data = $validator2->validate();
} catch (ValidationException $e) {
return redirect()->back()->withErrors($validator2)->withInput();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question