2.1-2.4: install spatie/laravel-translatable, migrate to JSON, update models & controllers
Deploy Backend / deploy (push) Failing after 1m52s
Deploy Backend / deploy (push) Failing after 1m52s
This commit is contained in:
1 parent
75af8220a7
commit
37dd2c9d54
17 files changed
+453
-285
No files matched your search
@@ -4,56 +4,19 @@ namespace App\Models\Website;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
class Skill extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, HasTranslations;
|
||||
|
||||
protected $table = 'website_skills'; // نام جدول
|
||||
protected $fillable = ['image', 'link', 'about_me_id', 'percentage']; // فیلدهایی که قابل پر کردن هستند
|
||||
protected $table = 'website_skills';
|
||||
protected $fillable = ['image', 'link', 'about_me_id', 'percentage'];
|
||||
|
||||
protected array $translatable = ['title', 'description'];
|
||||
|
||||
/**
|
||||
* ارتباط با جدول 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user