StudentResponsibleRequest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Rules\AdultBirthDate;
  4. use App\ValueObjects\Cpf;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. use Illuminate\Validation\Rule;
  7. class StudentResponsibleRequest extends FormRequest
  8. {
  9. public function rules(): array
  10. {
  11. return [
  12. 'student_id' => 'required|integer|exists:students,id',
  13. 'name' => 'required|string|max:255',
  14. 'birth_date' => ['required', 'date', new AdultBirthDate],
  15. 'cpf' => ['required', 'string', 'max:20', Cpf::rule()],
  16. 'gender' => 'nullable|string|in:male,female,other,no_preference',
  17. 'degree' => 'required|string|max:255',
  18. 'email' => [
  19. 'required',
  20. 'email',
  21. 'max:255',
  22. Rule::unique('student_responsibles', 'email')
  23. ->where(fn ($query) => $query->where('student_id', $this->input('student_id')))
  24. ->ignore($this->route('id')),
  25. ],
  26. 'phone' => 'required|string|max:20',
  27. 'street' => 'required|string|max:255',
  28. 'address_number' => 'nullable|string|max:20',
  29. 'postal_code' => 'required|string|max:10',
  30. 'neighborhood' => 'required|string|max:255',
  31. 'city_id' => 'required|integer|exists:cities,id',
  32. 'state_id' => 'required|integer|exists:states,id',
  33. 'complement' => 'nullable|string|max:255',
  34. 'notes' => 'nullable|string',
  35. ];
  36. }
  37. public function messages(): array
  38. {
  39. return [
  40. 'student_id.required' => 'O aluno é obrigatório.',
  41. 'student_id.exists' => 'Aluno não encontrado.',
  42. 'name.required' => 'O nome é obrigatório.',
  43. 'birth_date.required' => 'A data de nascimento é obrigatória.',
  44. 'cpf.required' => 'O CPF é obrigatório.',
  45. 'degree.required' => 'O grau de parentesco é obrigatório.',
  46. 'email.required' => 'O e-mail é obrigatório.',
  47. 'email.email' => 'Informe um e-mail válido.',
  48. 'phone.required' => 'O telefone é obrigatório.',
  49. 'street.required' => 'O endereço é obrigatório.',
  50. 'postal_code.required' => 'O CEP é obrigatório.',
  51. 'neighborhood.required' => 'O bairro é obrigatório.',
  52. 'city_id.required' => 'A cidade é obrigatória.',
  53. 'city_id.exists' => 'Cidade não encontrada.',
  54. 'state_id.required' => 'O estado é obrigatório.',
  55. 'state_id.exists' => 'Estado não encontrado.',
  56. ];
  57. }
  58. }