Optimierung 5.3 (Teil 2): Category::localizedName()

Name aus der locale-gefiltert geladenen Uebersetzung mit #id-Fallback als
Model-Methode. Ersetzt die identische Inline-Logik an 4 Stellen (Footer-Codes
und Kategorien jeweils create/edit).

Test: CategoryLocalizedNameTest.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-19 13:19:06 +00:00
parent 178adb00e2
commit abe9a0aa69
6 changed files with 32 additions and 4 deletions

View file

@ -46,6 +46,16 @@ class Category extends Model
return $this->hasMany(CategoryTranslation::class);
}
/**
* Name aus der bereits (locale-gefiltert) geladenen Übersetzung, mit
* `#id`-Fallback, falls keine Übersetzung vorliegt. Erwartet eine
* eager-geladene `translations`-Relation der gewünschten Sprache.
*/
public function localizedName(): string
{
return $this->translations->first()?->name ?? '#'.$this->id;
}
public function pressReleases(): HasMany
{
return $this->hasMany(PressRelease::class);