RegisterClientRequest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. 'zip_code' => 'required|string|max:20',
  19. 'number' => 'required|string|max:20',
  20. 'address' => 'required|string|max:255',
  21. 'district' => 'required|string|max:255',
  22. 'city' => 'required|string|max:255',
  23. 'state' => 'required|string|max:10',
  24. 'has_complement' => 'required|boolean',
  25. 'complement' => 'required|string|max:255',
  26. 'nickname' => 'sometimes|nullable|string|max:255',
  27. 'instructions' => 'sometimes|nullable|string|max:500',
  28. 'address_type' => 'sometimes|nullable|string|in:home,commercial,other',
  29. 'latitude' => 'sometimes|nullable|numeric',
  30. 'longitude' => 'sometimes|nullable|numeric',
  31. 'avatar' => 'sometimes|nullable|file|image|mimes:jpg,jpeg,png,webp|max:5120',
  32. ];
  33. }
  34. protected function prepareForValidation(): void
  35. {
  36. if (! $this->filled('has_complement')) {
  37. $this->merge(['has_complement' => false]);
  38. }
  39. }
  40. }