Files
voltcerto/app/Http/Requests/UpdateClientRequest.php
Luis Medon e488ae3342 Add feature tests, unit tests, and configuration for Laravel application
- Created ExampleTest and RoutesTest for basic application response and route testing.
- Implemented IsolatedDatabaseTestCase for isolated database testing.
- Added unit tests for various models and services including Contract, CPE, and LeadDetail.
- Developed request validation tests for CreateClientRequest, UpdateClientRequest, and ContractRequest.
- Introduced Vite configuration for asset management in the Laravel application.
2026-10-29 11:30:06 +00:00

84 lines
4.6 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateClientRequest extends FormRequest
{
protected function localizedMessage(string $key, string $fallback): string
{
if (function_exists('app') && app()->bound('translator')) {
return __($key, [], app()->getLocale()) ?: $fallback;
}
return $fallback;
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'tax_number' => 'required|digits:9|unique:clients,tax_number,' . $this->route('id'),
'email' => 'required|email',
'phone' => 'required|string|max:20',
'address' => 'required|string|max:255',
'contact_info' => 'nullable|string|max:255',
'notes' => 'nullable|string|max:500',
'seller_id' => 'required|exists:users,id',
'client_type_id' => 'required|exists:client_types,id',
'locality' => 'nullable|string|max:255'
];
}
/**
* Get custom error messages for validation rules.
*
* @return array
*/
public function messages(): array
{
return [
'name.required' => $this->localizedMessage('validation.custom.name.required', 'O nome é obrigatório.'),
'name.string' => $this->localizedMessage('validation.custom.name.string', 'O nome deve ser texto.'),
'name.max' => $this->localizedMessage('validation.custom.name.max', 'O nome não pode ter mais de 255 caracteres.'),
'tax_number.required' => $this->localizedMessage('validation.custom.tax_number.required', 'O NIF é obrigatório.'),
'tax_number.digits' => $this->localizedMessage('validation.custom.tax_number.digits', 'O NIF deve ter 9 dígitos.'),
'tax_number.unique' => $this->localizedMessage('validation.custom.tax_number.unique', 'Já existe um cliente com este NIF.'),
'email.required' => $this->localizedMessage('validation.custom.email.required', 'O e-mail é obrigatório.'),
'email.email' => $this->localizedMessage('validation.custom.email.email', 'O e-mail deve ser válido.'),
'phone.required' => $this->localizedMessage('validation.custom.phone.required', 'O telefone é obrigatório.'),
'phone.string' => $this->localizedMessage('validation.custom.phone.string', 'O telefone deve ser texto.'),
'phone.max' => $this->localizedMessage('validation.custom.phone.max', 'O telefone não pode ter mais de 20 caracteres.'),
'address.required' => $this->localizedMessage('validation.custom.address.required', 'A morada é obrigatória.'),
'address.string' => $this->localizedMessage('validation.custom.address.string', 'A morada deve ser texto.'),
'address.max' => $this->localizedMessage('validation.custom.address.max', 'A morada não pode ter mais de 255 caracteres.'),
'contact_info.string' => $this->localizedMessage('validation.custom.contact_info.string', 'As informações de contacto devem ser texto.'),
'contact_info.max' => $this->localizedMessage('validation.custom.contact_info.max', 'As informações de contacto não podem exceder 255 caracteres.'),
'notes.string' => $this->localizedMessage('validation.custom.notes.string', 'As notas devem ser texto.'),
'notes.max' => $this->localizedMessage('validation.custom.notes.max', 'As notas não podem exceder 500 caracteres.'),
'seller_id.required' => $this->localizedMessage('validation.custom.seller_id.required', 'O vendedor é obrigatório.'),
'seller_id.exists' => $this->localizedMessage('validation.custom.seller_id.exists', 'O vendedor selecionado não é válido.'),
'client_type_id.required' => $this->localizedMessage('validation.custom.client_type_id.required', 'O tipo de cliente é obrigatório.'),
'client_type_id.exists' => $this->localizedMessage('validation.custom.client_type_id.exists', 'O tipo de cliente selecionado não é válido.'),
'locality.string' => $this->localizedMessage('validation.custom.locality.string', 'A localidade deve ser texto.'),
'locality.max' => $this->localizedMessage('validation.custom.locality.max', 'A localidade não pode ter mais de 255 caracteres.'),
];
}
}