refactor(validation): implement centralized validation patterns across components

- Introduced `ValidationPatterns` class to standardize validation rules and messages for various fields across multiple components.
- Updated components including `General`, `StackForm`, `Create`, and `Show` to utilize the new validation patterns, ensuring consistent validation logic.
- Enhanced error messages for required fields and added regex validation for names and descriptions to improve user feedback.
- Adjusted styling in the `create.blade.php` view for better visual hierarchy.
This commit is contained in:
Andras Bacsai
2025-08-19 14:15:31 +02:00
parent eaee87d008
commit 5c4a265542
19 changed files with 659 additions and 250 deletions
+20 -4
View File
@@ -4,6 +4,7 @@ namespace App\Livewire\Team;
use App\Models\Team;
use App\Models\TeamInvitation;
use App\Support\ValidationPatterns;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
@@ -14,10 +15,25 @@ class Index extends Component
public Team $team;
protected $rules = [
'team.name' => 'required|min:3|max:255',
'team.description' => 'nullable|min:3|max:255',
];
protected function rules(): array
{
return [
'team.name' => ValidationPatterns::nameRules(),
'team.description' => ValidationPatterns::descriptionRules(),
];
}
protected function messages(): array
{
return array_merge(
ValidationPatterns::combinedMessages(),
[
'team.name.required' => 'The Name field is required.',
'team.name.regex' => 'The Name may only contain letters, numbers, spaces, dashes (-), underscores (_), dots (.), slashes (/), colons (:), and parentheses ().',
'team.description.regex' => 'The Description contains invalid characters. Only letters, numbers, spaces, and common punctuation (- _ . : / () \' " , ! ? @ # % & + = [] {} | ~ ` *) are allowed.',
]
);
}
protected $validationAttributes = [
'team.name' => 'name',