| Conditions | 5 |
| Paths | 5 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | public function handleForm(Request $request) |
||
| 13 | { |
||
| 14 | if (!$request->has('_form_')) { |
||
| 15 | throw new Exception('Invalid form request.'); |
||
| 16 | } |
||
| 17 | |||
| 18 | $formClass = $request->get('_form_'); |
||
| 19 | |||
| 20 | if (!class_exists($formClass)) { |
||
| 21 | throw new Exception("Form [{$formClass}] not exists."); |
||
| 22 | } |
||
| 23 | |||
| 24 | /** @var Form $form */ |
||
| 25 | $form = app($formClass); |
||
| 26 | |||
| 27 | if (!method_exists($form, 'handle')) { |
||
| 28 | throw new Exception("Form method {$formClass}::handle() not exists."); |
||
| 29 | } |
||
| 30 | |||
| 31 | if ($errors = $form->validate($request)) { |
||
| 32 | return back()->withInput()->withErrors($errors); |
||
| 33 | } |
||
| 34 | |||
| 35 | return $form->sanitize()->handle($request); |
||
| 36 | } |
||
| 37 | } |