StudentRequest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\ValueObjects\Cpf;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. class StudentRequest extends FormRequest
  6. {
  7. public function rules(): array
  8. {
  9. $rules = [
  10. 'avatar' => 'sometimes|nullable|image',
  11. 'birth_date' => 'sometimes|nullable|date',
  12. 'document_number' => 'sometimes|nullable|string|max:20',
  13. 'gender' => 'sometimes|nullable|string|in:no_preference,male,female,other',
  14. 'email' => 'sometimes|nullable|email',
  15. 'phone' => 'sometimes|nullable|string|max:20',
  16. 'postal_code' => 'sometimes|nullable|string|max:10',
  17. 'street' => 'sometimes|nullable|string|max:255',
  18. 'address_number' => 'sometimes|nullable|string|max:20',
  19. 'neighborhood' => 'sometimes|nullable|string|max:255',
  20. 'city_id' => 'sometimes|nullable|integer|exists:cities,id',
  21. 'state_id' => 'sometimes|nullable|integer|exists:states,id',
  22. 'complement' => 'sometimes|nullable|string|max:255',
  23. 'payer_name' => 'sometimes|nullable|string|max:255',
  24. 'how_did_you_know_us' => 'sometimes|nullable|string|in:referral,social_media,google,other',
  25. 'notes' => 'sometimes|nullable|string',
  26. 'responsible' => 'sometimes|nullable|array',
  27. 'responsible.name' => 'sometimes|nullable|string|max:255',
  28. 'responsible.birth_date' => 'sometimes|nullable|date',
  29. 'responsible.cpf' => ['sometimes', 'nullable', 'string', 'max:20', Cpf::rule()],
  30. 'responsible.gender' => 'sometimes|nullable|string|in:no_preference,male,female,other',
  31. 'responsible.degree' => 'sometimes|nullable|string|max:255',
  32. 'responsible.email' => 'sometimes|nullable|email',
  33. 'responsible.phone' => 'sometimes|nullable|string|max:20',
  34. 'responsible.postal_code' => 'sometimes|nullable|string|max:10',
  35. 'responsible.street' => 'sometimes|nullable|string|max:255',
  36. 'responsible.address_number' => 'sometimes|nullable|string|max:20',
  37. 'responsible.neighborhood' => 'sometimes|nullable|string|max:255',
  38. 'responsible.city_id' => 'sometimes|nullable|integer|exists:cities,id',
  39. 'responsible.state_id' => 'sometimes|nullable|integer|exists:states,id',
  40. 'responsible.complement' => 'sometimes|nullable|string|max:255',
  41. 'responsible.notes' => 'sometimes|nullable|string',
  42. ];
  43. if ($this->isMethod('post')) {
  44. $rules['name'] = 'required|string|max:255';
  45. $rules['email'] = 'sometimes|nullable|email|unique:students,email';
  46. } else {
  47. $rules['name'] = 'sometimes|string|max:255';
  48. }
  49. return $rules;
  50. }
  51. }