| Conditions | 6 |
| Paths | 1 |
| Total Lines | 25 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | public function rules(): array |
||
| 43 | { |
||
| 44 | $user = $this->user($this->route('guard')); |
||
| 45 | |||
| 46 | // Attach attribute rules |
||
| 47 | $user->getEntityAttributes()->each(function ($attribute, $attributeName) use (&$rules) { |
||
| 48 | switch ($attribute->type) { |
||
| 49 | case 'datetime': |
||
| 50 | $type = 'date'; |
||
| 51 | break; |
||
| 52 | case 'text': |
||
| 53 | case 'varchar': |
||
| 54 | $type = 'string'; |
||
| 55 | break; |
||
| 56 | default: |
||
| 57 | $type = $attribute->type; |
||
| 58 | break; |
||
| 59 | } |
||
| 60 | |||
| 61 | $rule = ($attribute->is_required ? 'required|' : 'nullable|').$type; |
||
| 62 | $rules[$attributeName.($attribute->is_collection ? '.*' : '')] = $rule; |
||
| 63 | }); |
||
| 64 | |||
| 65 | return $rules ?? []; |
||
| 66 | } |
||
| 67 | } |
||
| 68 |