<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;
use App\Models\News;
use Spatie\Translatable\HasTranslations;

class NewsPhoto extends Model
{
    use HasFactory, HasTranslations;

    protected $guarded = ['id'];
    public $timestamps = false;
    protected $appends = ['news_photo_img'];
    public $translatable = ['image_alt'];

    public function paragraph(){
        return $this->belongsTo(NewsParagraph::class);
    }
    protected function newsPhotoImg(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($this->image_url) ? null :Storage::disk('public')->url($this->image_url),
        );
    }
}
