StudentRequest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. 'birth_date' => 'sometimes|nullable|date',
  10. 'document_number' => 'sometimes|nullable|string|max:20',
  11. 'gender' => 'sometimes|nullable|string|in:no_preference,male,female,other',
  12. 'email' => 'sometimes|nullable|email',
  13. 'phone' => 'sometimes|nullable|string|max:20',
  14. 'postal_code' => 'sometimes|nullable|string|max:10',
  15. 'street' => 'sometimes|nullable|string|max:255',
  16. 'address_number' => 'sometimes|nullable|string|max:20',
  17. 'neighborhood' => 'sometimes|nullable|string|max:255',
  18. 'state_id' => 'sometimes|nullable|integer|exists:states,id',
  19. 'complement' => 'sometimes|nullable|string|max:255',
  20. 'payer_name' => 'sometimes|nullable|string|max:255',
  21. 'how_did_you_know_us' => 'sometimes|nullable|string|in:referral,social_media,google,other',
  22. 'notes' => 'sometimes|nullable|string',
  23. ];
  24. if ($this->isMethod('post')) {
  25. $rules['name'] = 'required|string|max:255';
  26. $rules['email'] = 'sometimes|nullable|email|unique:students,email';
  27. } else {
  28. $rules['name'] = 'sometimes|string|max:255';
  29. }
  30. return $rules;
  31. }
  32. }