Conditions | 6 |
Paths | 8 |
Total Lines | 27 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
27 | public function update(Request $request, $id) |
||
28 | { |
||
29 | $data = $this->config->getModel()::find($id); |
||
30 | $data->fill($request->all()); |
||
31 | |||
32 | foreach ($this->config->rows as $row) { |
||
33 | if (\in_array($row->name, $data->getFillable(), false) && ! isset($data->{$row->name})) { |
||
34 | if ($row instanceof FormDate) { |
||
35 | $data->{$row->name} = $request->input('date', date('Y-m-d')); |
||
36 | } else { |
||
37 | $data->{$row->name} = $request->input($row->name, $row->default); |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | $validator = Validator::make($data->toArray(), $this->config->getValid($id)); |
||
43 | if ($validator->fails()) { |
||
44 | return back()->withInput($request->except('password'))->withErrors($validator); |
||
45 | } |
||
46 | |||
47 | $data->save(); |
||
48 | event(new ComponentItemUpdated($this->config, $data, $request)); |
||
49 | MessageLarrock::success('Материал '.$request->input('title').' изменен'); |
||
50 | \Cache::flush(); |
||
51 | |||
52 | return back(); |
||
53 | } |
||
54 | } |
||
55 |