Conditions | 6 |
Paths | 1 |
Total Lines | 25 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | public function rules(): array |
||
27 | { |
||
28 | $user = $this->user($this->get('guard')); |
||
29 | |||
30 | // Attach attribute rules |
||
31 | $user->getEntityAttributes()->each(function ($attribute, $attributeSlug) use (&$rules) { |
||
32 | switch ($attribute->type) { |
||
33 | case 'datetime': |
||
34 | $type = 'date'; |
||
35 | break; |
||
36 | case 'text': |
||
37 | case 'varchar': |
||
38 | $type = 'string'; |
||
39 | break; |
||
40 | default: |
||
41 | $type = $attribute->type; |
||
42 | break; |
||
43 | } |
||
44 | |||
45 | $rule = ($attribute->is_required ? 'required|' : 'nullable|').$type; |
||
46 | $rules[$attributeSlug.($attribute->is_collection ? '.*' : '')] = $rule; |
||
47 | }); |
||
48 | |||
49 | return $rules ?? []; |
||
50 | } |
||
51 | } |
||
52 |