StudentRequest.php 3.0 KB

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