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

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

View File

@ -4,19 +4,47 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class AboutMe extends Model
{
use HasFactory, HasTranslations;
use HasFactory;
protected $table = 'website_about_me';
protected $fillable = ['image'];
protected $fillable = ['image',
'translations',];
protected array $translatable = ['title', 'description'];
public function skills()
{
return $this->hasMany(Skill::class);
}
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;
}
}

View File

@ -4,19 +4,47 @@
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;
}
}

View File

@ -4,14 +4,42 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class ProjectCategory extends Model
{
use HasFactory, HasTranslations;
use HasFactory;
protected $table = 'website_project_categories';
protected $fillable = ['image'];
protected $fillable = ['image',
'translations',];
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;
}
protected array $translatable = ['title', 'description'];
}

View File

@ -10,7 +10,8 @@ class Service extends Model
use HasFactory;
protected $table = 'website_services';
protected $fillable = ['imageSrc'];
protected $fillable = ['imageSrc',
'translations'];
protected $casts = [
'translations' => 'array',

View File

@ -4,19 +4,47 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class Skill extends Model
{
use HasFactory, HasTranslations;
use HasFactory;
protected $table = 'website_skills';
protected $fillable = ['image', 'link', 'about_me_id', 'percentage'];
protected $fillable = ['image', 'link', 'about_me_id', 'percentage',
'translations',];
protected array $translatable = ['title', 'description'];
public function aboutMe()
{
return $this->belongsTo(AboutMe::class, 'about_me_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;
}
}

View File

@ -12,6 +12,7 @@ public function run()
{
$aboutMe = AboutMe::create([
'image' => '/images/profile.png',
'translations' => [
'title' => [
'en' => 'About Me',
'fa' => 'درباره من',
@ -20,6 +21,7 @@ public function run()
'en' => 'With over 10 years of experience in web development, I bridge the gap between pixel-perfect frontend engineering and robust backend architecture. Specialized in refactoring legacy codebases, optimizing core web vitals, and building scalable enterprise-grade Next.js applications.',
'fa' => 'با بیش از ۱۰ سال تجربه در دنیای توسعه وب، مسیر کاری من ترکیبی از مهندسی دقیق فرانت‌اند و درک عمیق از معماری بک‌اند است. تخصص اصلی من در بازطراحی و Refactor کدهای پیچیده، بهینه‌سازی Performance پروژه‌های بزرگ Next.js و پیاده‌سازی زیرساخت‌های پایدار وب است.',
],
],
]);
$skills = [
@ -27,23 +29,29 @@ public function run()
'image' => '/images/frontend.png',
'percentage' => 100,
'link' => '#',
'translations' => [
'title' => ['en' => 'React / Next.js / TypeScript', 'fa' => 'React / Next.js / TypeScript'],
'description' => ['en' => 'Core Tech', 'fa' => 'تکنولوژی‌های اصلی'],
],
],
[
'image' => '/images/backend.png',
'percentage' => 100,
'link' => '#',
'translations' => [
'title' => ['en' => 'Laravel / PHP / MySQL', 'fa' => 'Laravel / PHP / MySQL'],
'description' => ['en' => 'Backend & Tools', 'fa' => 'بک‌اند و ابزارها'],
],
],
[
'image' => '/images/ui.png',
'percentage' => 100,
'link' => '#',
'translations' => [
'title' => ['en' => 'TDD / Clean Architecture', 'fa' => 'TDD / Clean Architecture'],
'description' => ['en' => 'Architecture & Others', 'fa' => 'معماری و سایر موارد'],
],
],
];
foreach ($skills as $skillData) {
@ -51,6 +59,3 @@ public function run()
}
}
}
}
}

View File

@ -11,33 +11,44 @@ public function run()
{
$categories = [
[
'image' => 'category1.jpg',
'translations' => [
'title' => ['en' => 'App Design', 'fa' => 'طراحی اپلیکیشن'],
'description' => ['en' => 'Description for App Design', 'fa' => 'توضیحات طراحی اپلیکیشن'],
],
],
[
'image' => 'category2.jpg',
'translations' => [
'title' => ['en' => 'Front End', 'fa' => 'فرانت اند'],
'description' => ['en' => 'Description for Front End', 'fa' => 'توضیحات فرانت اند'],
],
],
[
'image' => 'category3.jpg',
'translations' => [
'title' => ['en' => 'Backend', 'fa' => 'بک اند'],
'description' => ['en' => 'Description for Backend', 'fa' => 'توضیحات بک اند'],
],
],
[
'image' => 'category4.jpg',
'translations' => [
'title' => ['en' => 'Web Design', 'fa' => 'طراحی وب'],
'description' => ['en' => 'Description for Web Design', 'fa' => 'توضیحات طراحی وب'],
],
],
[
'image' => 'category5.jpg',
'translations' => [
'title' => ['en' => 'Graphic Design', 'fa' => 'طراحی گرافیک'],
'description' => ['en' => 'Description for Graphic Design', 'fa' => 'توضیحات طراحی گرافیک'],
],
],
];
foreach ($categories as $key => $category) {
ProjectCategory::create([
'image' => 'category' . ($key + 1) . '.jpg',
'title' => $category['title'],
'description' => $category['description'],
]);
foreach ($categories as $category) {
ProjectCategory::create($category);
}
}
}

View File

@ -20,6 +20,7 @@ public function run()
'category_id' => $category->id,
'image1' => 'project' . $i . '_image1.jpg',
'image2' => 'project' . $i . '_image2.jpg',
'translations' => [
'title' => [
'en' => 'Project ' . $i . ' - ' . $category->getTranslation('title', 'en'),
'fa' => 'پروژه ' . $i . ' - ' . $category->getTranslation('title', 'fa'),
@ -28,6 +29,7 @@ public function run()
'en' => 'Description for project ' . $i . ' in category ' . $category->getTranslation('title', 'en'),
'fa' => 'توضیحات پروژه ' . $i . ' برای دسته‌بندی ' . $category->getTranslation('title', 'fa'),
],
],
]);
}
}

View File

@ -12,6 +12,7 @@ public function run()
$services = [
[
'imageSrc' => '/images/ui-ux-vector.svg',
'translations' => [
'title' => [
'en' => 'Senior Frontend Engineering',
'fa' => 'توسعه فرانت‌اند ارشد',
@ -21,8 +22,10 @@ public function run()
'fa' => 'خلق SPAها و SSRهای بسیار سریع با Next.js، مدیریت استیت‌های پیچیده و بهینه‌سازی Core Web Vitals',
],
],
],
[
'imageSrc' => '/images/web-design-vector.svg',
'translations' => [
'title' => [
'en' => 'Backend & API Design',
'fa' => 'معماری و توسعه بک‌اند',
@ -32,8 +35,10 @@ public function run()
'fa' => 'طراحی APIهای ماژولار، امن و بهینه با Laravel و مدیریت دیتابیس‌های مقیاس‌پذیر',
],
],
],
[
'imageSrc' => '/images/app-design-vector.svg',
'translations' => [
'title' => [
'en' => 'Code Refactoring & Modernization',
'fa' => 'بازطراحی و مدرن‌سازی کد',
@ -43,6 +48,7 @@ public function run()
'fa' => 'تبدیل کدهای قدیمی و مگالیتی به معماری‌های کامپوننت‌محور، تمیز و تست‌پذیر',
],
],
],
];
foreach ($services as $serviceData) {