<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Page extends Model
{
    use HasFactory;
    protected $table = 'cms_pages';
    protected $fillable = ['title', 'title_ar', 'content', 'content_ar', 'status'];
    
    protected $translatable = ['title', 'content'];
    public function getAttributes()
    {
        foreach($this->translatable as $attribute) {
            $locale = app()->getLocale();
            $localizedKey = "{$attribute}_{$locale}";
            if (isset($this->attributes[$localizedKey])) {
                $this->attributes[$attribute] =  (empty($this->attributes[$localizedKey]))?$this->attributes["{$attribute}"]:$this->attributes[$localizedKey];
            }
        }
        return $this->attributes;
    }

    // You can add additional methods as needed for validation or manipulation
}
