RegisterClientRequest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Validation\Rule;
  5. class RegisterClientRequest extends FormRequest
  6. {
  7. public function rules(): array
  8. {
  9. return [
  10. 'code' => 'required|string|max:6',
  11. 'email' => [
  12. Rule::requiredIf(fn () => ! config('services.sms.enabled') || ! $this->filled('phone')),
  13. 'string', 'email', 'max:255',
  14. ],
  15. 'name' => 'required|string|max:255',
  16. 'phone' => 'required|string|max:20',
  17. 'document' => 'required|string|max:20',
  18. 'birth_date' => 'nullable|date|before:today',
  19. 'zip_code' => 'required|string|max:20',
  20. 'number' => 'required|string|max:20',
  21. 'address' => 'required|string|max:255',
  22. 'district' => 'required|string|max:255',
  23. 'city' => 'required|string|max:255',
  24. 'state' => 'required|string|max:10',
  25. 'has_complement' => 'required|boolean',
  26. 'complement' => 'required|string|max:255',
  27. 'nickname' => 'sometimes|nullable|string|max:255',
  28. 'instructions' => 'sometimes|nullable|string|max:500',
  29. 'address_type' => 'sometimes|nullable|string|in:home,commercial,other',
  30. 'latitude' => 'sometimes|nullable|numeric',
  31. 'longitude' => 'sometimes|nullable|numeric',
  32. 'avatar' => 'sometimes|nullable|file|image|mimes:jpg,jpeg,png,webp|max:5120',
  33. ];
  34. }
  35. protected function prepareForValidation(): void
  36. {
  37. if (! $this->filled('has_complement')) {
  38. $this->merge(['has_complement' => false]);
  39. }
  40. }
  41. }