| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Http\Requests;
- use App\Enums\PartnerAgreementStatusEnum;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Validation\Rule;
- class PartnerAgreementRequest extends FormRequest
- {
- public function rules(): array
- {
- $cnpjUnique = 'unique:partner_agreements,cnpj';
- if ($this->isMethod('put') && $this->route('id')) {
- $cnpjUnique = 'unique:partner_agreements,cnpj,' . $this->route('id');
- }
- $rules = [
- 'company_name' => 'sometimes|string|max:255',
- 'cnpj' => ['sometimes', 'nullable', 'string', 'max:18', $cnpjUnique],
- 'category_id' => 'sometimes|nullable|integer|exists:categories,id',
- 'responsible' => 'sometimes|nullable|string|max:255',
- 'discount_percentage' => 'sometimes|nullable|numeric|min:0|max:100',
- 'description' => 'sometimes|nullable|string',
- 'email' => 'sometimes|nullable|email|max:255',
- 'phone' => 'sometimes|nullable|string|max:20',
- 'whatsapp' => 'sometimes|nullable|string|max:20',
- 'website' => 'sometimes|nullable|string|max:255',
- 'address' => 'sometimes|nullable|string|max:255',
- 'neighborhood' => 'sometimes|nullable|string|max:255',
- 'city_id' => 'sometimes|nullable|integer|exists:cities,id',
- 'state_id' => 'sometimes|nullable|integer|exists:states,id',
- 'zip_code' => 'sometimes|nullable|string|max:9',
- 'working_hours' => 'sometimes|nullable|string|max:255',
- 'contract_start' => 'sometimes|nullable|date',
- 'contract_end' => 'sometimes|nullable|date|after_or_equal:contract_start',
- 'status' => ['sometimes', Rule::enum(PartnerAgreementStatusEnum::class)],
- ];
- if ($this->isMethod('post')) {
- $rules['company_name'] = 'required|string|max:255';
- }
- return $rules;
- }
- }
|