<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class Official extends Model
{
    protected $fillable = ['nama', 'jabatan', 'ttl', 'foto', 'urutan'];

    public function getFotoUrlAttribute(): ?string
    {
        if (!$this->foto) return null;
        if (str_starts_with($this->foto, 'http')) return $this->foto;
        return Storage::url($this->foto);
    }

    public static function ordered()
    {
        return static::orderBy('urutan')->get();
    }
}
