value; $bankAccountType = AccountTypeEnum::BANK_ACCOUNT->value; $accountTypes = implode(',', [$pixAccountType, $bankAccountType]); $bankAccountTypes = implode(',', [BankAccountTypeEnum::CHECKING->value, BankAccountTypeEnum::SAVINGS->value]); if ($this->account_type == AccountTypeEnum::PIX->value) { $rules = [ 'account_type' => "sometimes|in:{$accountTypes}", 'pix_key' => "required|string|max:255|required_if:account_type,{$pixAccountType}", 'bank_account_type' => "nullable|required_if:account_type,{$bankAccountType}|in:{$bankAccountTypes}", 'agency' => "nullable|string|max:255|required_if:account_type,{$bankAccountType}", 'account' => "nullable|string|max:255|required_if:account_type,{$bankAccountType}", 'digit' => "nullable|string|max:255|required_if:account_type,{$bankAccountType}", ]; } else { $rules = [ 'account_type' => "sometimes|in:{$accountTypes}", 'pix_key' => "nullable|string|max:255|required_if:account_type,{$pixAccountType}", 'bank_account_type' => "sometimes|required_if:account_type,{$bankAccountType}|in:{$bankAccountTypes}", 'agency' => "sometimes|string|max:255|required_if:account_type,{$bankAccountType}", 'account' => "sometimes|string|max:255|required_if:account_type,{$bankAccountType}", 'digit' => "sometimes|string|max:255|required_if:account_type,{$bankAccountType}", ]; } if ($this->isMethod('post')) { $rules['provider_id'] = 'required|exists:providers,id'; }; return $rules; } }