RegisterProviderRequest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Enums\WorkingPeriodEnum;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. class RegisterProviderRequest extends FormRequest
  7. {
  8. public function rules(): array
  9. {
  10. $rules = [
  11. 'email' => 'sometimes|email',
  12. 'phone' => 'sometimes|string|nullable|max:20',
  13. 'name' => 'required|string|max:255',
  14. 'code' => 'required|string|max:6',
  15. 'document' => ['required', 'string', 'max:20'],
  16. 'rg' => 'required|string|max:20',
  17. 'birth_date' => 'required|date|before:today',
  18. 'zip_code' => 'required|string|max:20',
  19. 'address' => 'required|string|max:255',
  20. 'has_complement' => 'sometimes|boolean',
  21. 'complement' => 'nullable|string|max:255',
  22. 'nickname' => 'nullable|string|max:255',
  23. 'instructions' => 'nullable|string',
  24. 'address_type' => ['required', Rule::in(['home', 'commercial', 'other'])],
  25. 'city' => 'nullable|string|max:255',
  26. 'state' => 'nullable|string|max:2',
  27. 'daily_price_8h' => 'required|numeric|min:100|max:500',
  28. 'daily_price_6h' => 'required|numeric|min:0',
  29. 'daily_price_4h' => 'required|numeric|min:0',
  30. 'daily_price_2h' => 'required|numeric|min:0',
  31. 'services_types_ids' => 'sometimes|array',
  32. 'services_types_ids.*' => [
  33. 'integer',
  34. Rule::exists('service_types', 'id')->where(function ($query) {
  35. $query->whereNull('deleted_at')->where('is_active', true);
  36. }),
  37. ],
  38. 'service_types_ids' => 'sometimes|array',
  39. 'service_types_ids.*' => [
  40. 'integer',
  41. Rule::exists('service_types', 'id')->where(function ($query) {
  42. $query->whereNull('deleted_at')->where('is_active', true);
  43. }),
  44. ],
  45. 'working_days' => 'required|array|min:1',
  46. 'working_days.*.day' => 'required|integer|min:0|max:6',
  47. 'working_days.*.period' => ['required', Rule::in([WorkingPeriodEnum::MORNING->value, WorkingPeriodEnum::AFTERNOON->value])],
  48. 'selfie_base64' => 'required|string',
  49. 'document_front_base64' => 'required|string',
  50. 'document_back_base64' => 'required|string',
  51. 'is_approved' => 'sometimes|boolean',
  52. ];
  53. if (!$this->has('email')) {
  54. $rules['phone'] = 'required|string|max:20';
  55. $rules['email'] = 'nullable';
  56. }
  57. if (!$this->has('phone')) {
  58. $rules['email'] = 'required|email';
  59. $rules['phone'] = 'nullable';
  60. }
  61. return $rules;
  62. }
  63. }