40 lines
919 B
PHP
40 lines
919 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Page extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'slug',
|
|
'title_ar',
|
|
'title_en',
|
|
'content_ar',
|
|
'content_en',
|
|
];
|
|
|
|
/**
|
|
* Get the title in the specified locale, with fallback to Arabic.
|
|
*/
|
|
public function getTitle(?string $locale = null): string
|
|
{
|
|
$locale ??= app()->getLocale();
|
|
|
|
return $locale === 'en' ? ($this->title_en ?? $this->title_ar) : $this->title_ar;
|
|
}
|
|
|
|
/**
|
|
* Get the content in the specified locale, with fallback to Arabic.
|
|
*/
|
|
public function getContent(?string $locale = null): string
|
|
{
|
|
$locale ??= app()->getLocale();
|
|
|
|
return $locale === 'en' ? ($this->content_en ?? $this->content_ar ?? '') : ($this->content_ar ?? '');
|
|
}
|
|
}
|