parsaaghayi-backend/app/Models/Website/AboutMe.php

57 lines
1.3 KiB
PHP

<?php
namespace App\Models\Website;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AboutMe extends Model
{
use HasFactory;
protected $table = 'website_about_me';
protected $fillable = ['image'];
/**
* ارتباط با ترجمه‌ها
*/
public function translations()
{
return $this->hasMany(AboutMeTranslation::class, 'about_me_id');
}
/**
* گرفتن ترجمه بر اساس زبان فعلی
*/
public function getTranslation($locale)
{
if ($this->relationLoaded('translations')) {
return $this->translations->firstWhere('locale', $locale);
}
return $this->translations()->where('locale', $locale)->first();
}
/**
* گرفتن عنوان بر اساس زبان فعلی
*/
public function getTitle($locale)
{
$translation = $this->getTranslation($locale);
return $translation ? $translation->title : null;
}
/**
* گرفتن توضیحات بر اساس زبان فعلی
*/
public function getDescription($locale)
{
$translation = $this->getTranslation($locale);
return $translation ? $translation->description : null;
}
public function skills()
{
return $this->hasMany(Skill::class);
}
}