56 lines
1.2 KiB
PHP
56 lines
1.2 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',
|
|
'translations',];
|
|
|
|
|
|
|
|
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 hasTranslation(string $key, string $locale): bool
|
|
{
|
|
$translations = $this->translations;
|
|
return isset($translations[$key][$locale]);
|
|
}
|
|
|
|
public function getTitleAttribute()
|
|
{
|
|
return $this->translations['title'] ?? null;
|
|
}
|
|
|
|
public function getDescriptionAttribute()
|
|
{
|
|
return $this->translations['description'] ?? null;
|
|
}
|
|
|
|
} |