feat(validation): centralize validation patterns for names and descriptions

- Introduced `ValidationPatterns` class to standardize validation rules and messages for name and description fields across the application.
- Updated various components and models to utilize the new validation patterns, ensuring consistent sanitization and validation logic.
- Replaced the `HasSafeNameAttribute` trait with `HasSafeStringAttribute` to enhance attribute handling and maintain consistency in name sanitization.
- Enhanced the `CleanupNames` command to align with the new validation rules, allowing for a broader range of valid characters in names.
This commit is contained in:
Andras Bacsai
2025-08-19 12:14:48 +02:00
parent 0bb9ee4327
commit 38c0641734
30 changed files with 238 additions and 132 deletions

View File

@@ -2,8 +2,7 @@
namespace App\Models;
use App\Traits\HasSafeNameAttribute;
use Illuminate\Database\Eloquent\Casts\Attribute;
use App\Traits\HasSafeStringAttribute;
use OpenApi\Attributes as OA;
#[OA\Schema(
@@ -20,7 +19,7 @@ use OpenApi\Attributes as OA;
)]
class Environment extends BaseModel
{
use HasSafeNameAttribute;
use HasSafeStringAttribute;
protected $guarded = [];
@@ -122,10 +121,8 @@ class Environment extends BaseModel
return $this->hasMany(Service::class);
}
protected function name(): Attribute
protected function customizeName($value)
{
return Attribute::make(
set: fn (string $value) => str($value)->lower()->trim()->replace('/', '-')->toString(),
);
return str($value)->lower()->trim()->replace('/', '-')->toString();
}
}