57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Website;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Skill extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'website_skills'; // نام جدول
|
|
protected $fillable = ['image', 'link', 'about_me_id', 'percentage']; // فیلدهایی که قابل پر کردن هستند
|
|
|
|
/**
|
|
* ارتباط با جدول AboutMe
|
|
*/
|
|
public function aboutMe()
|
|
{
|
|
return $this->belongsTo(AboutMe::class, 'about_me_id');
|
|
}
|
|
|
|
/**
|
|
* ارتباط با جدول ترجمهها
|
|
*/
|
|
public function translations()
|
|
{
|
|
return $this->hasMany(SkillTranslation::class, 'skill_id');
|
|
}
|
|
|
|
/**
|
|
* گرفتن ترجمه بر اساس زبان فعلی
|
|
*/
|
|
public function getTranslation($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;
|
|
}
|
|
}
|