StudentRegistrationDraftRequest.php 2.0 KB

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