51 lines
1.1 KiB
PHP
51 lines
1.1 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',
|
|
'translations',];
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
}
|