StudentResponsibleRequest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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' => [
  16. 'required',
  17. 'string',
  18. 'max:20',
  19. Cpf::rule(),
  20. Rule::unique('student_responsibles', 'cpf')
  21. ->where(fn ($query) => $query->where('student_id', $this->input('student_id')))
  22. ->ignore($this->route('id')),
  23. ],
  24. 'gender' => 'nullable|string|in:male,female,other,no_preference',
  25. 'degree' => 'required|string|max:255',
  26. 'company' => 'required|string|max:255',
  27. 'profession' => 'required|string|max:255',
  28. 'email' => [
  29. 'required',
  30. 'email',
  31. 'max:255',
  32. Rule::unique('student_responsibles', 'email')
  33. ->where(fn ($query) => $query->where('student_id', $this->input('student_id')))
  34. ->ignore($this->route('id')),
  35. ],
  36. 'phone' => 'required|string|max:20',
  37. 'street' => 'required|string|max:255',
  38. 'address_number' => 'nullable|string|max:20',
  39. 'postal_code' => 'required|string|max:10',
  40. 'neighborhood' => 'required|string|max:255',
  41. 'city_id' => 'required|integer|exists:cities,id',
  42. 'state_id' => 'required|integer|exists:states,id',
  43. 'complement' => 'nullable|string|max:255',
  44. 'notes' => 'nullable|string',
  45. ];
  46. }
  47. public function messages(): array
  48. {
  49. return [
  50. 'student_id.required' => 'O aluno é obrigatório.',
  51. 'student_id.exists' => 'Aluno não encontrado.',
  52. 'name.required' => 'O nome é obrigatório.',
  53. 'birth_date.required' => 'A data de nascimento é obrigatória.',
  54. 'cpf.required' => 'O CPF é obrigatório.',
  55. 'degree.required' => 'O grau de parentesco é obrigatório.',
  56. 'company.required' => 'A empresa é obrigatória.',
  57. 'profession.required' => 'A profissão é obrigatória.',
  58. 'email.required' => 'O e-mail é obrigatório.',
  59. 'email.email' => 'Informe um e-mail válido.',
  60. 'phone.required' => 'O telefone é obrigatório.',
  61. 'street.required' => 'O endereço é obrigatório.',
  62. 'postal_code.required' => 'O CEP é obrigatório.',
  63. 'neighborhood.required' => 'O bairro é obrigatório.',
  64. 'city_id.required' => 'A cidade é obrigatória.',
  65. 'city_id.exists' => 'Cidade não encontrada.',
  66. 'state_id.required' => 'O estado é obrigatório.',
  67. 'state_id.exists' => 'Estado não encontrado.',
  68. ];
  69. }
  70. }