fix: remove HasTranslations trait, use translations JSON in models + seeders

This commit is contained in:
DevOps committed 2026-06-28 17:37:08 +00:00
1 parent ebd4bd19ed
commit 223a4f5640
9 files changed
+214 -77

No files matched your search

+32 -4
View File
@@ -4,19 +4,47 @@ namespace App\Models\Website;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class Project extends Model
{
use HasFactory, HasTranslations;
use HasFactory;
protected $table = 'website_projects';
protected $fillable = ['category_id', 'image1', 'image2'];
protected $fillable = ['category_id', 'image1', 'image2',
'translations',];
protected array $translatable = ['title', 'description'];
public function category()
{
return $this->belongsTo(ProjectCategory::class, 'category_id');
}
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;
}
}