StudentRegistrationDraftRequest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\ValueObjects\Cpf;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. class StudentRegistrationDraftRequest extends FormRequest
  6. {
  7. protected function prepareForValidation(): void
  8. {
  9. $documentNumber = $this->input('document_number');
  10. if (is_string($documentNumber)) {
  11. $this->merge([
  12. 'document_number' => preg_replace('/\D/', '', $documentNumber),
  13. ]);
  14. }
  15. }
  16. public function rules(): array
  17. {
  18. return [
  19. 'registration_draft_token' => 'sometimes|nullable|uuid',
  20. 'name' => 'required|string|max:255',
  21. 'birth_date' => 'required|date',
  22. 'document_number' => ['sometimes', 'nullable', 'string', 'max:20', Cpf::rule(), 'unique:students,document_number'],
  23. 'gender' => 'sometimes|nullable|string|in:no_preference,male,female,other',
  24. 'email' => 'sometimes|nullable|email|unique:students,email',
  25. 'phone' => 'sometimes|nullable|string|max:20',
  26. 'postal_code' => 'sometimes|nullable|string|max:10',
  27. 'street' => 'sometimes|nullable|string|max:255',
  28. 'address_number' => 'sometimes|nullable|string|max:20',
  29. 'neighborhood' => 'sometimes|nullable|string|max:255',
  30. 'city_id' => 'sometimes|nullable|integer|exists:cities,id',
  31. 'state_id' => 'sometimes|nullable|integer|exists:states,id',
  32. 'complement' => 'sometimes|nullable|string|max:255',
  33. 'payer_name' => 'sometimes|nullable|string|max:255',
  34. 'how_did_you_know_us' => 'sometimes|nullable|string|in:referral,social_media,google,other',
  35. 'notes' => 'sometimes|nullable|string',
  36. ];
  37. }
  38. }