PartnerAgreementRequest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Enums\PartnerAgreementStatusEnum;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. class PartnerAgreementRequest extends FormRequest
  7. {
  8. public function rules(): array
  9. {
  10. $cnpjUnique = 'unique:partner_agreements,cnpj';
  11. if ($this->isMethod('put') && $this->route('id')) {
  12. $cnpjUnique = 'unique:partner_agreements,cnpj,' . $this->route('id');
  13. }
  14. $rules = [
  15. 'company_name' => 'sometimes|string|max:255',
  16. 'cnpj' => ['sometimes', 'nullable', 'string', 'max:18', $cnpjUnique],
  17. 'category_id' => 'sometimes|nullable|integer|exists:categories,id',
  18. 'responsible' => 'sometimes|nullable|string|max:255',
  19. 'discount_percentage' => 'sometimes|nullable|numeric|min:0|max:100',
  20. 'description' => 'sometimes|nullable|string',
  21. 'email' => 'sometimes|nullable|email|max:255',
  22. 'phone' => 'sometimes|nullable|string|max:20',
  23. 'whatsapp' => 'sometimes|nullable|string|max:20',
  24. 'website' => 'sometimes|nullable|string|max:255',
  25. 'address' => 'sometimes|nullable|string|max:255',
  26. 'neighborhood' => 'sometimes|nullable|string|max:255',
  27. 'city_id' => 'sometimes|nullable|integer|exists:cities,id',
  28. 'state_id' => 'sometimes|nullable|integer|exists:states,id',
  29. 'zip_code' => 'sometimes|nullable|string|max:9',
  30. 'working_hours' => 'sometimes|nullable|string|max:255',
  31. 'contract_start' => 'sometimes|nullable|date',
  32. 'contract_end' => 'sometimes|nullable|date|after_or_equal:contract_start',
  33. 'status' => ['sometimes', Rule::enum(PartnerAgreementStatusEnum::class)],
  34. ];
  35. if ($this->isMethod('post')) {
  36. $rules['company_name'] = 'required|string|max:255';
  37. }
  38. return $rules;
  39. }
  40. }