From 4c5f6cfe10d9a23b1af18ad5fe5fc344326c6908 Mon Sep 17 00:00:00 2001 From: DevOps Date: Sun, 28 Jun 2026 15:59:20 +0000 Subject: [PATCH] fix: update Service model for translations JSON column --- app/Models/Website/Service.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Models/Website/Service.php b/app/Models/Website/Service.php index de023e1..805ea66 100644 --- a/app/Models/Website/Service.php +++ b/app/Models/Website/Service.php @@ -4,14 +4,37 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Spatie\Translatable\HasTranslations; class Service extends Model { - use HasFactory, HasTranslations; + use HasFactory; protected $table = 'website_services'; protected $fillable = ['imageSrc']; - protected array $translatable = ['title', 'description']; -} + protected $casts = [ + 'translations' => 'array', + ]; + + public function getTranslation(string $key, string $locale, bool $useFallbackLocale = true): mixed + { + $translations = $this->translations; + if (isset($translations[$key][$locale])) { + return $translations[$key][$locale]; + } + if ($useFallbackLocale && isset($translations[$key]['en'])) { + return $translations[$key]['en']; + } + return null; + } + + public function getTitleAttribute() + { + return $this->translations['title'] ?? null; + } + + public function getDescriptionAttribute() + { + return $this->translations['description'] ?? null; + } +} \ No newline at end of file