| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Http\Requests;
- use App\Enums\PartnerAgreementStatusEnum;
- use App\Models\PartnerAgreement;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Validation\Rule;
- class PartnerAgreementRequest extends FormRequest
- {
- public function rules(): array
- {
- $cnpjUnique = 'unique:partner_agreements,cnpj';
- $partnerId = PartnerAgreement::where('user_id', auth()->id())->value('id');
- if ($this->isMethod('put') && $partnerId) {
- $cnpjUnique = 'unique:partner_agreements,cnpj,' . $partnerId;
- }
- $rules = [
- 'user_name' => 'sometimes|nullable|string|max:255',
- 'user_email' => 'sometimes|nullable|email|max:255',
- 'user_password' => 'sometimes|nullable|string|min:6',
- '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';
- $rules['user_name'] = 'required|string|max:255';
- $rules['user_email'] = 'required|email|max:255|unique:users,email';
- $rules['user_password'] = 'required|string|min:6';
- }
- return $rules;
- }
- }
|