<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Spatie\Translatable\HasTranslations;

class Badge extends Model
{
    use HasTranslations;

    protected $guarded = ["id"];
    public $translatable = ["title"];
    protected $appends = ["img_url_link"];

    protected function imgUrlLink(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($this->img_url) ? null :Storage::url($this->img_url),
        );
    }

    public function projects()
    {
        return $this->morphedByMany(Project::class, 'badgeable');
    }

}
