UnitPartnerRequest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\ValueObjects\Cpf;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. class UnitPartnerRequest extends FormRequest
  6. {
  7. public function rules(): array
  8. {
  9. $isCreate = $this->isMethod('POST');
  10. $rules = [
  11. 'unit_id' => 'sometimes|integer|exists:units,id',
  12. 'name' => 'sometimes|required|string|max:255',
  13. 'social_name' => 'sometimes|nullable|string|max:255',
  14. 'role' => 'sometimes|nullable|string|max:100',
  15. 'cpf' => ['sometimes', 'required', 'string', 'max:20', Cpf::rule()],
  16. 'rg' => 'sometimes|nullable|string|max:30',
  17. 'birth_date' => 'sometimes|nullable|date',
  18. 'participation' => 'sometimes|nullable|numeric|min:0|max:100',
  19. 'email' => 'sometimes|nullable|email|max:255',
  20. 'secondary_email' => 'sometimes|nullable|email|max:255',
  21. 'phone_number' => 'sometimes|nullable|string|max:20',
  22. 'cell_number' => 'sometimes|nullable|string|max:20',
  23. 'postal_code' => 'sometimes|nullable|string|max:9',
  24. 'street' => 'sometimes|nullable|string|max:255',
  25. 'address_number' => 'sometimes|nullable|string|max:20',
  26. 'neighborhood' => 'sometimes|nullable|string|max:255',
  27. 'complement' => 'sometimes|nullable|string|max:255',
  28. 'city_id' => 'sometimes|nullable|integer|exists:cities,id',
  29. 'state_id' => 'sometimes|nullable|integer|exists:states,id',
  30. 'avatar' => 'sometimes|nullable|image|max:2048',
  31. ];
  32. if ($isCreate) {
  33. $rules['name'] = 'required|string|max:255';
  34. $rules['cpf'] = ['required', 'string', 'max:20', Cpf::rule()];
  35. }
  36. return $rules;
  37. }
  38. }