From 6d6749964e256e9658610bf2fbf9f3004b4dcd3f Mon Sep 17 00:00:00 2001 From: lukibeg Date: Sat, 8 Nov 2025 19:54:10 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20valida=20dados=20do=20formul=C3=A1rio?= =?UTF-8?q?=20para=20adi=C3=A7=C3=A3o=20de=20clients.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/Forms/ClientForm.php | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 app/Livewire/Forms/ClientForm.php diff --git a/app/Livewire/Forms/ClientForm.php b/app/Livewire/Forms/ClientForm.php new file mode 100644 index 0000000..2a8c0d0 --- /dev/null +++ b/app/Livewire/Forms/ClientForm.php @@ -0,0 +1,86 @@ +toArray(); + $data['has_call_center'] = (bool) $client->has_call_center; + $data['has_voice_gateway'] = (bool) $client->has_voice_gateway; + $data['has_fop2'] = (bool) $client->has_fop2; + + $this->fill($data); + } + + // 4. ADICIONADO: Método de Regras + /** + * Define as regras de validação para o formulário. + */ + public function rules() + { + return [ + 'client_name' => 'required|string|max:255', + 'legal_name' => 'required|string|max:255', + 'cnpj' => 'required|string|max:20|unique:clients,cnpj', + 'profile_image_path' => 'nullable|file|mimes:jpeg,png,bmp,gif,svg,webp|max:2048', // 2MB Max 'pbx_hosting' => 'nullable|string|max:255', + 'activation_date' => 'nullable|date', + 'carrier' => 'nullable|string|max:255', + 'access_type' => 'nullable|string|max:255', + 'server_ip' => 'nullable|ip', + 'root_password' => 'nullable|string', + 'has_call_center' => 'boolean', + 'has_voice_gateway' => 'boolean', + 'has_fop2' => 'boolean', + 'modules' => 'nullable|json', + 'whatsapp_number' => 'nullable|string|max:20', + 'whatsapp_activation_date' => 'nullable|date', + ]; + } + + // 5. ADICIONADO: Método de Mensagens Customizadas + /** + * Define as mensagens de erro customizadas. + */ + public function messages() + { + return [ + 'client_name.required' => 'O campo Nome Fantasia é obrigatório.', + 'client_name.max' => 'O Nome Fantasia não pode ter mais que 255 caracteres.', + + 'cnpj.unique' => 'Este CNPJ já está cadastrado em outro cliente.', + + 'profile_image_path.image' => 'O arquivo deve ser uma imagem válida (jpg, png, etc.).', + 'profile_image_path.max' => 'A imagem não pode ser maior que 2MB.', + + 'server_ip.ip' => 'Por favor, insira um endereço de IP válido.', + 'modules.json' => 'O campo módulos deve conter um formato JSON válido.', + + '*.date' => 'Por favor, insira uma data válida.', + '*.boolean' => 'Este campo deve ser verdadeiro ou falso.', + ]; + } +}