fix: update Service model for translations JSON column
All checks were successful
Deploy Backend / deploy (push) Successful in 3m12s

This commit is contained in:
DevOps 2026-06-28 15:59:20 +00:00
parent 3d99998036
commit 58cb185db5

View File

@ -4,14 +4,37 @@
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class Service extends Model class Service extends Model
{ {
use HasFactory, HasTranslations; use HasFactory;
protected $table = 'website_services'; protected $table = 'website_services';
protected $fillable = ['imageSrc']; 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;
}
} }