| Total Complexity | 5 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class SaveRequest extends FormRequest |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Determine if the user is authorized to make this request. |
||
| 11 | * |
||
| 12 | * @return bool |
||
| 13 | */ |
||
| 14 | public function authorize() |
||
| 15 | { |
||
| 16 | if ($this->route()->getName() === 'users.register') { |
||
| 17 | return true; |
||
| 18 | } else { |
||
| 19 | return auth('web')->user(); |
||
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Base rules for a save request. |
||
| 25 | * |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | private $baseRules = [ |
||
| 29 | 'name' => 'required|string', |
||
| 30 | 'email' => 'email', |
||
| 31 | 'phone' => 'required|string|unique:fg_users,phone', |
||
| 32 | 'image' => 'base64image', |
||
| 33 | ]; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Get the validation rules that apply to the request. |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | public function rules() |
||
| 41 | { |
||
| 42 | if ($this->route()->getName() === 'users.register') { |
||
| 43 | return $this->baseRules; |
||
| 44 | } else { |
||
| 45 | return array_merge($this->baseRules, [ |
||
| 46 | 'phone' => 'required|string', |
||
| 47 | ]); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | public function messages() |
||
| 55 | ]; |
||
| 56 | } |
||
| 57 | } |
||
| 58 |