StudentRequest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. 'state_id' => 'sometimes|nullable|integer|exists:states,id',
  20. 'complement' => 'sometimes|nullable|string|max:255',
  21. 'payer_name' => 'sometimes|nullable|string|max:255',
  22. 'how_did_you_know_us' => 'sometimes|nullable|string|in:referral,social_media,google,other',
  23. 'notes' => 'sometimes|nullable|string',
  24. ];
  25. if ($this->isMethod('post')) {
  26. $rules['name'] = 'required|string|max:255';
  27. $rules['email'] = 'sometimes|nullable|email|unique:students,email';
  28. } else {
  29. $rules['name'] = 'sometimes|string|max:255';
  30. }
  31. return $rules;
  32. }
  33. }